Re: [Rd] Tail Call Elimination?

2011-04-17 Thread Dominick Samperi
The Scheme-inspired function callCC may support this to some extent, but
the R man page on this function is very sketchy. Examples have been
posted by the author of callCC, so you might want to search the archives.

Dominick

On Sun, Apr 17, 2011 at 1:34 AM, Mohit Dayal  wrote:
> Dear R-programmers,
>
> I am trying to program a Newton-Raphson in R (yes, i will try GSL, not right
> now), and it would be a real boon if R had tail call elimination, so that a
> recursive program has a guarantee not to fail due to stack overflows, given
> how slow loops in R are. I did look at the documentation, but could not find
> a reason for it.
>
> Regards,
> Mohit Dayal
> Researcher
> Applied Statistics & Computing Lab
> ISB
>
>        [[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] DESCRIPTION file and Rd examples

2011-04-17 Thread Dario Strbenac
It turns out what I needed was IRanges in the Imports: field. I assumed that 
require(GenomicRanges) at the top of my function would, as a result of loading 
GenomicRanges, implicitly already know about all the IRanges classes, because 
GenomicRanges itself depends on them.

 Original message 
>Date: Fri, 15 Apr 2011 20:34:54 -0700
>From: Martin Morgan   
>Subject: Re: [Rd] DESCRIPTION file and Rd examples  
>To: Simon Urbanek 
>Cc: d.strbe...@garvan.org.au, r-devel@r-project.org
>
>On 04/15/2011 11:18 AM, Simon Urbanek wrote:
>>
>> On Apr 14, 2011, at 11:00 PM, Dario Strbenac wrote:
>>
>>> I have a confusing error from R CMD check that I don't get when running the 
>>> example manually by hand.
>>>
>>> In the \examples section of an Rd file, I create a GRanges object, then I 
>>> call a function with the GRanges object, whose first 2 lines are
>>>
>>> require(GenomicRanges)
>>
>> require() is doesn't guarantee that the package will load, so I think what 
>> you meant to write was more
>>
>> if (require(GenomicRanges, quietly=TRUE)) {
>>   ...
>>
>>> annoDF<- as.data.frame(anno) # anno is the GRanges object.
>>>
>>> and that second line gives:
>>>
>>> Error in as.data.frame.default(anno) :
>>>   cannot coerce class 'structure("GRanges", package = "GenomicRanges")' 
>>> into a data.frame
>>> Calls: annoGR2DF ... annoGR2DF ->  .local ->  as.data.frame ->  
>>> as.data.frame.default
>
>Try IRanges::as.data.frame(anno)
>
>I'm guessing that your call finds base::as.data.frame, perhaps because 
>some earlier example has already require'd GenomicRanges, and that it's 
>definition of as.data.frame has been masked some time in between.
>
>It's too complicated to debug in detail; R CMD check produces a file 
>.Rcheck/-Ex.R that contains the compiled example code, and it 
>is in the evaluation of this file that the error occurs. So you could 
>dissect it to discover the gory details.
>
>Martin
>
>>>
>>> I have GenomicRanges listed in my Imports: field, and IRanges in the 
>>> Suggests: of the DESCRIPTION file (it's require()d elsewhere). I'm trying 
>>> to avoid putting packages in Depends: , so my package loads fast. Any tips 
>>> of what I'm not understanding properly ?
>>>
>>> Thanks.
>>>
>>> --
>>> Dario Strbenac
>>> Research Assistant
>>> Cancer Epigenetics
>>> Garvan Institute of Medical Research
>>> Darlinghurst NSW 2010
>>> Australia
>>>
>>> __
>>> R-devel@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
>-- 
>Computational Biology
>Fred Hutchinson Cancer Research Center
>1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
>
>Location: M1-B861
>Telephone: 206 667-2793


--
Dario Strbenac
Research Assistant
Cancer Epigenetics
Garvan Institute of Medical Research
Darlinghurst NSW 2010
Australia

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] DESCRIPTION file and Rd examples

2011-04-17 Thread Thomas Lumley
On Mon, Apr 18, 2011 at 2:00 PM, Dario Strbenac
 wrote:
> It turns out what I needed was IRanges in the Imports: field. I assumed that 
> require(GenomicRanges) at the top of my function would, as a result of 
> loading GenomicRanges, implicitly already know about all the IRanges classes, 
> because GenomicRanges itself depends on them.

If GenomicRanges just imports IRanges (rather than using
library()/require()) then the IRanges functions won't be exported to
your package.  This is a Good Thing -- you only get the function
redefinitions you ask for, rather than everything in the dependency
tree.

-thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] R script in batch mode

2011-04-17 Thread jusce
Hello All!

I'm a new R user, with no much experience.
I have a R script (downloaded from internet) which has user interaction
using "readline()" function.
So as I have to run it repeatdly (with some different options) I was
planning to do it on a BATCH mode.

Is there any way to answer the "readline()" questions from a batch file?

How do I do that?

I'm using R under Linux.

Thanks,
Jose

--
View this message in context: 
http://r.789695.n4.nabble.com/R-script-in-batch-mode-tp3456471p3456471.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Patching "update.packages" to enable updating of only a user defined subset of packages

2011-04-17 Thread Tal Galili
Hello dear R developers,

I recently found out that it is not possible to limit update.packages() to
update only a few packages at a time.

The patch offered simply adds a 'subset' parameter and the statement bounded
within "if(!missing(subset))" to implement it.
The code is pasted bellow (and also attached as an .r file).

Might this patch be considered valuable to be added to R?


(in the code bellow I called the function "update.packages.2" so to not mask
the original update.packages)


With much respect,
Tal

###


update.packages.2 <-
function (lib.loc = NULL, repos = getOption("repos"), contriburl =
contrib.url(repos,
type), method, instlib = NULL, ask = TRUE, available = NULL,
oldPkgs = NULL, ..., checkBuilt = FALSE, type = getOption("pkgType"),
subset)
{
force(ask)
text.select <- function(old) {
update <- NULL
for (k in seq_len(nrow(old))) {
cat(old[k, "Package"], ":\n", "Version", old[k, "Installed"],
"installed in", old[k, "LibPath"], if (checkBuilt)
  paste("built under R", old[k, "Built"]), "\n",
"Version", old[k, "ReposVer"], "available at",
simplifyRepos(old[k, "Repository"], type))
cat("\n")
answer <- substr(readline("Update (y/N/c)?  "), 1L,
1L)
if (answer == "c" | answer == "C") {
cat("cancelled by user\n")
return(invisible())
}
if (answer == "y" | answer == "Y")
update <- rbind(update, old[k, ])
}
update
}
if (is.null(lib.loc))
lib.loc <- .libPaths()
if (is.null(available))
available <- available.packages(contriburl = contriburl,
method = method)
if (is.null(oldPkgs)) {
oldPkgs <- old.packages(lib.loc = lib.loc, contriburl = contriburl,
method = method, available = available, checkBuilt = checkBuilt)
if (is.null(oldPkgs))
return(invisible())
}
else if (!(is.matrix(oldPkgs) && is.character(oldPkgs)))
stop("invalid 'oldPkgs'; must be a result from old.packages()")
 if(!missing(subset)) # if the user uses 'subset'
 {
if(mode(subset) != "character") stop("'subset' must be a character vector
(with names of packages)")
 ss <- oldPkgs[,"Package"] %in% subset # are there any old packages that the
user would have liked to update?
 if(!any(ss)) {
cat("There are no available new updates for the packages you have entered \n
")
 return(invisible())
} # if not - then we can end the function here
 oldPkgs <- oldPkgs[ss,] # else - we can go on, but this time only use a
subset of the oldPkgs.
 if(sum(ss)==1) oldPkgs <- t(oldPkgs) # in case there is only 1 package to
update, make sure the object "oldPkgs" is of the correct form (6 columns
instead of 1 vector)
 }
update <- if (is.character(ask) && ask == "graphics") {
if (.Platform$OS.type == "windows" || .Platform$GUI ==
"AQUA" || (capabilities("tcltk") && capabilities("X11"))) {
k <- select.list(oldPkgs[, 1L], oldPkgs[, 1L], multiple = TRUE,
title = "Packages to be updated", graphics = TRUE)
oldPkgs[match(k, oldPkgs[, 1L]), , drop = FALSE]
}
else text.select(oldPkgs)
}
else if (isTRUE(ask))
text.select(oldPkgs)
else oldPkgs
if (length(update)) {
if (is.null(instlib))
instlib <- update[, "LibPath"]
libs <- unique(instlib)
for (l in libs) install.packages(update[instlib == l,
"Package"], l, contriburl = contriburl, method = method,
available = available, ..., type = type)
}
}

# Example:
# old.packages()
# update.packages.2(subset = "MASS")








Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel