[Rd] CRAN packages with invalid maintainer address
Emails to Edgar Acuna <[EMAIL PROTECTED]>, Federico C. F. Calboli <[EMAIL PROTECTED]>, Hao Wu <[EMAIL PROTECTED]>, Lopaka Lee <[EMAIL PROTECTED]>, Maria Kocherginsky <[EMAIL PROTECTED]>, as maintainers of CRAN packages with QC problems that need addressing for the upcoming 2.3.0 release failed yesterday. If you are one of these, or know how to reach these, pls let me know. -k __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
Hi, forget about the below details. It is not related to the fact that the function is returned from a function. Sorry about that. I've been troubleshooting soo much I've been shoting over the target. Here is a much smaller reproducible example: x <- 1:10 y <- 1:10 + rnorm(length(x)) sp <- smooth.spline(x=x, y=y) ypred <- predict(sp$fit, x) # [1] 2.325181 2.756166 ... ypred2 <- predict(sp$fit, c(0,x)) # Error in Recall(object, xrange) : couldn't find # function "predict.smooth.spline.fit" /Henrik On 4/5/06, Henrik Bengtsson <[EMAIL PROTECTED]> wrote: > Hi, > > yesterday I got very useful feedback on what is the best way to return > a function from a function. > > Now, I run into a problem calling a returned function that down the > stream uses Recall(). Below is a self-contained example. I took away > yesterday's code for returning a minimal environment for the function, > because that is not related to this problem. > > getPredictor <- function(x, y) { > sp <- smooth.spline(x=x, y=y, keep.data=FALSE) > function(x, ...) predict(sp$fit, x, ...)$y > } > > # Simulate data > x <- 1:10 > y <- 1:10 + rnorm(length(x)) > > # Estimate predictor function > fcn <- getPredictor(x,y) > > # No extrapolation => no Recall() > ypred <- fcn(x) > print(ypred) > # Gives: # [1] 2.325181 2.756166 ... > > # With extrapolation => Recall() > xextrap <- c(0,x) > ypred <- fcn(xextrap) > # Gives: # Error in Recall(object, xrange) : couldn't find > # function "predict.smooth.spline.fit" > > To see what's the function looks like, do > > pfcn <- getAnywhere("predict.smooth.spline.fit")$obj[[2]] > page(pfcn) > > A workaround is to set the predict.smooth.spline.fit() in .GlobalEnv, i.e. > > predict.smooth.spline.fit <- pfcn > > Does Recall() have a problem because predict.smooth.spline.fit() is > not exported, or what is going on? Are there alternatives to the > above workaround? I can see how such a workaround can become very > complicated with complex functions where it is hard to predict what > functions are called when. > > /Henrik > > PS, may I suggest to modify page() so that > 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. > -- Henrik Bengtsson Mobile: +46 708 909208 (+2h UTC) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Return function from function and Recall()
Hi, yesterday I got very useful feedback on what is the best way to return a function from a function. Now, I run into a problem calling a returned function that down the stream uses Recall(). Below is a self-contained example. I took away yesterday's code for returning a minimal environment for the function, because that is not related to this problem. getPredictor <- function(x, y) { sp <- smooth.spline(x=x, y=y, keep.data=FALSE) function(x, ...) predict(sp$fit, x, ...)$y } # Simulate data x <- 1:10 y <- 1:10 + rnorm(length(x)) # Estimate predictor function fcn <- getPredictor(x,y) # No extrapolation => no Recall() ypred <- fcn(x) print(ypred) # Gives: # [1] 2.325181 2.756166 ... # With extrapolation => Recall() xextrap <- c(0,x) ypred <- fcn(xextrap) # Gives: # Error in Recall(object, xrange) : couldn't find # function "predict.smooth.spline.fit" To see what's the function looks like, do pfcn <- getAnywhere("predict.smooth.spline.fit")$obj[[2]] page(pfcn) A workaround is to set the predict.smooth.spline.fit() in .GlobalEnv, i.e. predict.smooth.spline.fit <- pfcn Does Recall() have a problem because predict.smooth.spline.fit() is not exported, or what is going on? Are there alternatives to the above workaround? I can see how such a workaround can become very complicated with complex functions where it is hard to predict what functions are called when. /Henrik PS, may I suggest to modify page() so that 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Integration of C and Fortran
Prof Brian Ripley wrote: > Is > >>the enter point Fortran "orderdata_" absent of the loading table. > > a manual translation, and was the underscore there in the original (I > think it should be, but am just checking). The extra underscore added is the default behavior of many fortran compilers, to avoid symbol name collision - I believe this is actually mentioned very briefly in "writing R extensions" - here is the details from the relevant section of the documentation of gfortran (gcc 4.x's fortran front end): === Options for Code Generation Conventions `-fno-underscoring' Do not transform names of entities specified in the Fortran source file by appending underscores to them. With `-funderscoring' in effect, `gfortran' appends one underscore to external names with no underscores. This is done to ensure compatibility with code produced by many UNIX Fortran compilers. Use of `-fno-underscoring' is not recommended unless you are experimenting with issues such as integration of (GNU) Fortran into existing system environments (vis-a-vis existing libraries, tools, and so on). `-fsecond-underscore' By default, `gfortran' appends an underscore to external names. If this option is used `gfortran' appends two underscores to names with underscores and one underscore to external names with no underscores ... === > > What do nm -g mpackage.so tell you is actually exported from the shared > object (here called 'mypackage.so')? I suspect that will reveal a > mismatch of names. > > On Mon, 3 Apr 2006, Sebastien Durand wrote: > >> Dear all, >> >> I am running R : Copyright 2005, >> Version 2.2.1 (2005-12-20 r36812) >> ISBN 3-900051-07-0 >> On a mac 10.4.5 >> >> I am having trouble with my package. >> >> The trouble is the following: >> >> In my package I have integrated three files in my src folder. >> 1- simplematch.C a .C file >> 2- ordering.f a fortran file >> 3- Makevars : PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) >> I am not sure if that last file is really useful!? >> >> When I use the R CMD SHLIB command on both these >> source code files, the resulting compiled .so >> files when loads fine with the dyn.load function. >> At last when I use either the >> .C("simplematch",...) and >> .Fortran("ordering",...) command everything >> works... >> >> Now here comes trouble: >> >> When I do the R CMD INSTALL command, my package install. >> The .C command works but when I run the .Fortran command I get: >> >> Error in .Fortran("orderdata", d = as.double(d), >> as.integer(n), rowscore = as.double(rowscore)) : >> the enter point Fortran "orderdata_" absent of the loading table. >> >> What should I do to make sure that upon the installation of my package my >> Fortran function will appear in the load table... >> >> Thanks a lot. >> >> Sébastien Durand >> >> __ >> 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > Hi, > > forget about the below details. It is not related to the fact that > the function is returned from a function. Sorry about that. I've > been troubleshooting soo much I've been shoting over the target. Here > is a much smaller reproducible example: > > x <- 1:10 > y <- 1:10 + rnorm(length(x)) > sp <- smooth.spline(x=x, y=y) > ypred <- predict(sp$fit, x) > # [1] 2.325181 2.756166 ... > ypred2 <- predict(sp$fit, c(0,x)) > # Error in Recall(object, xrange) : couldn't find > # function "predict.smooth.spline.fit" It seems Recall is not searching (via findFun) from the right environment, but at a quick glance it is not obvious to me why. You can replace Recall by predict.smooth.spline.fit for now. As for >> PS, may I suggest to modify page() so that >> 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. it is rather tricky. page() takes a name aka symbol as its argument (and is thereby S-compatible), and also works with a bare character string (undocumented). What you have here is a call that does not even return a function. It is more reasonable that stats:::predict.smooth.spline.fit should work, and it is also a call. I have in the past thought about special-casing that, but it is a valid name (you would have to back-quote it, but it does work). So one possible way out would be to use get() on a name and evaluate calls, e.g. page <- function(x, method = c("dput", "print"), ...) { subx <- substitute(x) have_object <- FALSE if(is.call(subx)) { object <- x have_object <- TRUE subx <- deparse(subx) } else { if(is.character(x)) subx <- x else if(is.name(subx)) subx <- deparse(subx) if (!is.character(subx) || length(subx) != 1) stop("'page' requires a name, call or character string") parent <- parent.frame() if(exists(subx, envir = parent, inherits=TRUE)) { object <- get(subx, envir = parent, inherits=TRUE) have_object <- TRUE } } if(have_object) { method <- match.arg(method) file <- tempfile("Rpage.") if(method == "dput") dput(object, file) else { sink(file) print(object) sink() } file.show(file, title = subx, delete.file = TRUE, ...) } else stop(gettextf("no object named '%s' to show", subx), domain = NA) } which also allows 1-element character vectors (and I am not entirely sure we want that). > > /Henrik > > > On 4/5/06, Henrik Bengtsson <[EMAIL PROTECTED]> wrote: >> Hi, >> >> yesterday I got very useful feedback on what is the best way to return >> a function from a function. >> >> Now, I run into a problem calling a returned function that down the >> stream uses Recall(). Below is a self-contained example. I took away >> yesterday's code for returning a minimal environment for the function, >> because that is not related to this problem. >> >> getPredictor <- function(x, y) { >> sp <- smooth.spline(x=x, y=y, keep.data=FALSE) >> function(x, ...) predict(sp$fit, x, ...)$y >> } >> >> # Simulate data >> x <- 1:10 >> y <- 1:10 + rnorm(length(x)) >> >> # Estimate predictor function >> fcn <- getPredictor(x,y) >> >> # No extrapolation => no Recall() >> ypred <- fcn(x) >> print(ypred) >> # Gives: # [1] 2.325181 2.756166 ... >> >> # With extrapolation => Recall() >> xextrap <- c(0,x) >> ypred <- fcn(xextrap) >> # Gives: # Error in Recall(object, xrange) : couldn't find >> # function "predict.smooth.spline.fit" >> >> To see what's the function looks like, do >> >> pfcn <- getAnywhere("predict.smooth.spline.fit")$obj[[2]] >> page(pfcn) >> >> A workaround is to set the predict.smooth.spline.fit() in .GlobalEnv, i.e. >> >> predict.smooth.spline.fit <- pfcn >> >> Does Recall() have a problem because predict.smooth.spline.fit() is >> not exported, or what is going on? Are there alternatives to the >> above workaround? I can see how such a workaround can become very >> complicated with complex functions where it is hard to predict what >> functions are called when. >> >> /Henrik >> >> PS, may I suggest to modify page() so that >> 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. >> > > > -- > Henrik Bengtsson > Mobile: +46 708 909208 (+2h UTC) > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
> Prof Brian Ripley writes: > On Wed, 5 Apr 2006, Henrik Bengtsson wrote: >> Hi, >> >> forget about the below details. It is not related to the fact that >> the function is returned from a function. Sorry about that. I've >> been troubleshooting soo much I've been shoting over the target. Here >> is a much smaller reproducible example: >> >> x <- 1:10 >> y <- 1:10 + rnorm(length(x)) >> sp <- smooth.spline(x=x, y=y) >> ypred <- predict(sp$fit, x) >> # [1] 2.325181 2.756166 ... >> ypred2 <- predict(sp$fit, c(0,x)) >> # Error in Recall(object, xrange) : couldn't find >> # function "predict.smooth.spline.fit" > It seems Recall is not searching (via findFun) from the right > environment, but at a quick glance it is not obvious to me why. You > can replace Recall by predict.smooth.spline.fit for now. > As for >>> PS, may I suggest to modify page() so that >>> 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. > it is rather tricky. page() takes a name aka symbol as its argument > (and is thereby S-compatible), and also works with a bare character > string (undocumented). What you have here is a call that does not > even return a function. It is more reasonable that > stats:::predict.smooth.spline.fit should work, and it is also a call. > I have in the past thought about special-casing that, but it is a > valid name (you would have to back-quote it, but it does work). So > one possible way out would be to use get() on a name and evaluate > calls, e.g. > page <- function(x, method = c("dput", "print"), ...) > { > subx <- substitute(x) > have_object <- FALSE > if(is.call(subx)) { > object <- x > have_object <- TRUE > subx <- deparse(subx) > } else { > if(is.character(x)) subx <- x > else if(is.name(subx)) subx <- deparse(subx) > if (!is.character(subx) || length(subx) != 1) > stop("'page' requires a name, call or character string") > parent <- parent.frame() > if(exists(subx, envir = parent, inherits=TRUE)) { > object <- get(subx, envir = parent, inherits=TRUE) > have_object <- TRUE > } > } > if(have_object) { > method <- match.arg(method) > file <- tempfile("Rpage.") > if(method == "dput") > dput(object, file) > else { > sink(file) > print(object) > sink() > } > file.show(file, title = subx, delete.file = TRUE, ...) > } else > stop(gettextf("no object named '%s' to show", subx), domain = NA) > } > which also allows 1-element character vectors (and I am not entirely > sure we want that). There was a similar issue with prompt() (actually, its default method) for which I ended up "temporarily" providing the following (argh): else { name <- substitute(object) if (is.name(name)) as.character(name) else if (is.call(name) && (as.character(name[[1]]) %in% c("::", ":::", "getAnywhere"))) { name <- as.character(name) name[length(name)] } else stop("cannot determine a usable name") } Best -k __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > > > Hi, > > > > forget about the below details. It is not related to the fact that > > the function is returned from a function. Sorry about that. I've > > been troubleshooting soo much I've been shoting over the target. Here > > is a much smaller reproducible example: > > > > x <- 1:10 > > y <- 1:10 + rnorm(length(x)) > > sp <- smooth.spline(x=x, y=y) > > ypred <- predict(sp$fit, x) > > # [1] 2.325181 2.756166 ... > > ypred2 <- predict(sp$fit, c(0,x)) > > # Error in Recall(object, xrange) : couldn't find > > # function "predict.smooth.spline.fit" > > It seems Recall is not searching (via findFun) from the right environment, > but at a quick glance it is not obvious to me why. > You can replace Recall by predict.smooth.spline.fit for now. More troubleshooting shows that by dispatching directly on 'sp' and not 'sp$fit' works. The reason that I do not want to do this is related to my questions yesterday that I want to keep the memory usage down and 'sp' hold quite some extra data even with keep.data=FALSE. Example show how it works: x <- 1:10 y <- 1:10 + rnorm(length(x)) sp <- smooth.spline(x=x, y=y) The following two calls work: ypred1 <- predict(sp, x) ypred2 <- predict(sp, c(0,x)) They dispatch on predict.smooth.spline(), which in turn calls predict(sp$fit, ...) which dispatch on predict.smooth,spline.fit(); > getAnywhere("predict.smooth.spline") A single object matching 'predict.smooth.spline' was found It was found in the following places registered S3 method for predict from namespace stats namespace:stats with value function (object, x, deriv = 0, ...) { if (missing(x)) { if (deriv == 0) return(object[c("x", "y")]) else x <- object$x } fit <- object$fit if (is.null(fit)) stop("not a valid \"smooth.spline\" object") else predict(fit, x, deriv, ...) } Trying to do the same without the first step, that is, to call predict(sp$fit, ...) to dispatch on predict.smooth,spline.fit() directly, then the second will fail due to the Recall(); ypred3 <- predict(sp$fit, x) ypred4 <- predict(sp$fit, c(0,x)) # Error! Note that both predict.smooth.spline() and predict.smooth.spline.fit() are under the "namespace hood", i.e. not exported. So, no apparent difference there. To avoid the overhead of some of the elements of 'sp' I create a minimal 'smooth.spline' object like this: fit <- structure(list(fit=sp$fit), class=class(sp)) ypred5 <- predict(fit, x) ypred6 <- predict(fit, c(0,x)) # Error! and it all works. I don't really like to fake objects like this, although allowed in S3. But for now it's ok. However, it would be interesting to know/understands what is going on. /Henrik [snip] > > > > /Henrik > > > > > > On 4/5/06, Henrik Bengtsson <[EMAIL PROTECTED]> wrote: > >> Hi, > >> > >> yesterday I got very useful feedback on what is the best way to return > >> a function from a function. > >> > >> Now, I run into a problem calling a returned function that down the > >> stream uses Recall(). Below is a self-contained example. I took away > >> yesterday's code for returning a minimal environment for the function, > >> because that is not related to this problem. > >> > >> getPredictor <- function(x, y) { > >> sp <- smooth.spline(x=x, y=y, keep.data=FALSE) > >> function(x, ...) predict(sp$fit, x, ...)$y > >> } > >> > >> # Simulate data > >> x <- 1:10 > >> y <- 1:10 + rnorm(length(x)) > >> > >> # Estimate predictor function > >> fcn <- getPredictor(x,y) > >> > >> # No extrapolation => no Recall() > >> ypred <- fcn(x) > >> print(ypred) > >> # Gives: # [1] 2.325181 2.756166 ... > >> > >> # With extrapolation => Recall() > >> xextrap <- c(0,x) > >> ypred <- fcn(xextrap) > >> # Gives: # Error in Recall(object, xrange) : couldn't find > >> # function "predict.smooth.spline.fit" > >> > >> To see what's the function looks like, do > >> > >> pfcn <- getAnywhere("predict.smooth.spline.fit")$obj[[2]] > >> page(pfcn) > >> > >> A workaround is to set the predict.smooth.spline.fit() in .GlobalEnv, i.e. > >> > >> predict.smooth.spline.fit <- pfcn > >> > >> Does Recall() have a problem because predict.smooth.spline.fit() is > >> not exported, or what is going on? Are there alternatives to the > >> above workaround? I can see how such a workaround can become very > >> complicated with complex functions where it is hard to predict what > >> functions are called when. > >> > >> /Henrik > >> > >> PS, may I suggest to modify page() so that > >> 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. > >> > > > > > > -- > > Henrik Bengtsson > > Mobile: +46 708 909208 (+2h UTC) > > > > __ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > > > -- > Brian D. Ripley, [EMAIL PROTECTED] > Professor of Applied Statistics, http://www.stat
[Rd] page() (Was: Re: predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall()))
Here I think S3 dispatch is very natural. Try the following: page <- function(x, method = c("dput", "print"), ...) UseMethod("page") page.getAnywhere <- function(x, ..., idx=NULL) { name <- x$name; objects <- x$obj; if (length(objects) == 0) stop("no object named '", name, "' was found"); if (is.null(idx)) { # Include all non-duplicated objects found idx <- (1:length(objects))[!x$dups]; } for (ii in idx) { title <- paste(name, " (", x$where[ii], ")", sep=""); eval(substitute({ object <- x$obj[[ii]]; page(object, ...); }, list(object=as.name(title; } } page.default <- utils::page; page(getAnywhere("predict.smooth.spline.fit")) You can have page.function(), page.character(), page.environment(), etc. and make these call page.default() indirectly. What I think would be a very useful add on is to add an argument 'title' for which you can set/override the title. Then the "ugly" substitute() calls could be limited to one specific case; where a "default" object is passed and no title is set. If you want to, I could play around with a bit. /Henrik On 4/5/06, Kurt Hornik <[EMAIL PROTECTED]> wrote: > > Prof Brian Ripley writes: > > > On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > >> Hi, [snip] > > As for > > >>> PS, may I suggest to modify page() so that > >>> 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. > > > it is rather tricky. page() takes a name aka symbol as its argument > > (and is thereby S-compatible), and also works with a bare character > > string (undocumented). What you have here is a call that does not > > even return a function. It is more reasonable that > > stats:::predict.smooth.spline.fit should work, and it is also a call. > > I have in the past thought about special-casing that, but it is a > > valid name (you would have to back-quote it, but it does work). So > > one possible way out would be to use get() on a name and evaluate > > calls, e.g. > > > page <- function(x, method = c("dput", "print"), ...) > > { > > subx <- substitute(x) > > have_object <- FALSE > > if(is.call(subx)) { > > object <- x > > have_object <- TRUE > > subx <- deparse(subx) > > } else { > > if(is.character(x)) subx <- x > > else if(is.name(subx)) subx <- deparse(subx) > > if (!is.character(subx) || length(subx) != 1) > > stop("'page' requires a name, call or character string") > > parent <- parent.frame() > > if(exists(subx, envir = parent, inherits=TRUE)) { > > object <- get(subx, envir = parent, inherits=TRUE) > > have_object <- TRUE > > } > > } > > if(have_object) { > > method <- match.arg(method) > > file <- tempfile("Rpage.") > > if(method == "dput") > > dput(object, file) > > else { > > sink(file) > > print(object) > > sink() > > } > > file.show(file, title = subx, delete.file = TRUE, ...) > > } else > > stop(gettextf("no object named '%s' to show", subx), domain = NA) > > } > > > which also allows 1-element character vectors (and I am not entirely > > sure we want that). > > There was a similar issue with prompt() (actually, its default method) > for which I ended up "temporarily" providing the following (argh): > > else { > name <- substitute(object) > if (is.name(name)) > as.character(name) > else if (is.call(name) && (as.character(name[[1]]) %in% > c("::", ":::", "getAnywhere"))) { > name <- as.character(name) > name[length(name)] > } > else stop("cannot determine a usable name") > } > > Best > -k > > __ > 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] page() (Was: Re: predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall()))
On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > Here I think S3 dispatch is very natural. Try the following: I don't: it is documented to work on a name not an object. > page <- function(x, method = c("dput", "print"), ...) UseMethod("page") > > page.getAnywhere <- function(x, ..., idx=NULL) { > name <- x$name; > objects <- x$obj; > > if (length(objects) == 0) >stop("no object named '", name, "' was found"); > > if (is.null(idx)) { ># Include all non-duplicated objects found >idx <- (1:length(objects))[!x$dups]; > } > > for (ii in idx) { >title <- paste(name, " (", x$where[ii], ")", sep=""); >eval(substitute({ > object <- x$obj[[ii]]; > page(object, ...); >}, list(object=as.name(title; > } > } > > page.default <- utils::page; > > page(getAnywhere("predict.smooth.spline.fit")) > > You can have page.function(), page.character(), page.environment(), > etc. and make these call page.default() indirectly. What I think > would be a very useful add on is to add an argument 'title' for which > you can set/override the title. Then the "ugly" substitute() calls > could be limited to one specific case; where a "default" object is > passed and no title is set. > > If you want to, I could play around with a bit. > > /Henrik > > On 4/5/06, Kurt Hornik <[EMAIL PROTECTED]> wrote: >>> Prof Brian Ripley writes: >> >>> On Wed, 5 Apr 2006, Henrik Bengtsson wrote: Hi, > > [snip] > >>> As for >> > PS, may I suggest to modify page() so that > 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. >> >>> it is rather tricky. page() takes a name aka symbol as its argument >>> (and is thereby S-compatible), and also works with a bare character >>> string (undocumented). What you have here is a call that does not >>> even return a function. It is more reasonable that >>> stats:::predict.smooth.spline.fit should work, and it is also a call. >>> I have in the past thought about special-casing that, but it is a >>> valid name (you would have to back-quote it, but it does work). So >>> one possible way out would be to use get() on a name and evaluate >>> calls, e.g. >> >>> page <- function(x, method = c("dput", "print"), ...) >>> { >>> subx <- substitute(x) >>> have_object <- FALSE >>> if(is.call(subx)) { >>> object <- x >>> have_object <- TRUE >>> subx <- deparse(subx) >>> } else { >>> if(is.character(x)) subx <- x >>> else if(is.name(subx)) subx <- deparse(subx) >>> if (!is.character(subx) || length(subx) != 1) >>> stop("'page' requires a name, call or character string") >>> parent <- parent.frame() >>> if(exists(subx, envir = parent, inherits=TRUE)) { >>> object <- get(subx, envir = parent, inherits=TRUE) >>> have_object <- TRUE >>> } >>> } >>> if(have_object) { >>> method <- match.arg(method) >>> file <- tempfile("Rpage.") >>> if(method == "dput") >>> dput(object, file) >>> else { >>> sink(file) >>> print(object) >>> sink() >>> } >>> file.show(file, title = subx, delete.file = TRUE, ...) >>> } else >>> stop(gettextf("no object named '%s' to show", subx), domain = NA) >>> } >> >>> which also allows 1-element character vectors (and I am not entirely >>> sure we want that). >> >> There was a similar issue with prompt() (actually, its default method) >> for which I ended up "temporarily" providing the following (argh): >> >> else { >> name <- substitute(object) >> if (is.name(name)) >> as.character(name) >> else if (is.call(name) && (as.character(name[[1]]) %in% >> c("::", ":::", "getAnywhere"))) { >> name <- as.character(name) >> name[length(name)] >> } >> else stop("cannot determine a usable name") >> } >> >> Best >> -k >> >> __ >> 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 > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: >> On Wed, 5 Apr 2006, Henrik Bengtsson wrote: >> >>> Hi, >>> >>> forget about the below details. It is not related to the fact that >>> the function is returned from a function. Sorry about that. I've >>> been troubleshooting soo much I've been shoting over the target. Here >>> is a much smaller reproducible example: >>> >>> x <- 1:10 >>> y <- 1:10 + rnorm(length(x)) >>> sp <- smooth.spline(x=x, y=y) >>> ypred <- predict(sp$fit, x) >>> # [1] 2.325181 2.756166 ... >>> ypred2 <- predict(sp$fit, c(0,x)) >>> # Error in Recall(object, xrange) : couldn't find >>> # function "predict.smooth.spline.fit" >> >> It seems Recall is not searching (via findFun) from the right environment, >> but at a quick glance it is not obvious to me why. >> You can replace Recall by predict.smooth.spline.fit for now. > > More troubleshooting shows that by dispatching directly on 'sp' and > not 'sp$fit' works. The reason that I do not want to do this is > related to my questions yesterday that I want to keep the memory usage > down and 'sp' hold quite some extra data even with keep.data=FALSE. Ahah! So you are not using this as intended, and I had not spotted this. Now I understand: you are calling predict, which finds predict.smooth.spline.fit via method registration, and dispatches it in the environment used to call predict, .GlobalEnv, where of course it is not visible. Then Recall uses that environment, but attempts to call the method directly. If you call this as intended, predict is called from the body of predict.smooth.spline where predict.smooth.spline.fit is visible. I am afraid that you should not be expecting to be able to subvert things this way. [...] Now, I was a little surprised that Recall() needed to do a lookup, but R's context only contains the name of the called function and not (a pointer to) the function. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > > > On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > >> On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > >> > >>> Hi, > >>> > >>> forget about the below details. It is not related to the fact that > >>> the function is returned from a function. Sorry about that. I've > >>> been troubleshooting soo much I've been shoting over the target. Here > >>> is a much smaller reproducible example: > >>> > >>> x <- 1:10 > >>> y <- 1:10 + rnorm(length(x)) > >>> sp <- smooth.spline(x=x, y=y) > >>> ypred <- predict(sp$fit, x) > >>> # [1] 2.325181 2.756166 ... > >>> ypred2 <- predict(sp$fit, c(0,x)) > >>> # Error in Recall(object, xrange) : couldn't find > >>> # function "predict.smooth.spline.fit" > >> > >> It seems Recall is not searching (via findFun) from the right environment, > >> but at a quick glance it is not obvious to me why. > >> You can replace Recall by predict.smooth.spline.fit for now. > > > > More troubleshooting shows that by dispatching directly on 'sp' and > > not 'sp$fit' works. The reason that I do not want to do this is > > related to my questions yesterday that I want to keep the memory usage > > down and 'sp' hold quite some extra data even with keep.data=FALSE. > > Ahah! So you are not using this as intended, and I had not spotted this. Neither did I ;) > Now I understand: you are calling predict, which finds > predict.smooth.spline.fit via method registration, and dispatches it in > the environment used to call predict, .GlobalEnv, where of course it is > not visible. Then Recall uses that environment, but attempts to call the > method directly. > > If you call this as intended, predict is called from the body of > predict.smooth.spline where predict.smooth.spline.fit is visible. > > I am afraid that you should not be expecting to be able to subvert things > this way. One could argue that it should not be possible to dispatch to a non-exported method the way I did. If UseMethod() would use the same search path as the calling expression in the parent frame (and not from "within" the environment where the generic function lives), then the predict() would fail right away. However, I think it is a very risky business to make such modifications to UseMethod(), because there are probably unknown side effects to this. /Henrik > [...] > > Now, I was a little surprised that Recall() needed to do a lookup, but R's > context only contains the name of the called function and not (a pointer > to) the function. > > -- > Brian D. Ripley, [EMAIL PROTECTED] > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > > -- Henrik Bengtsson Mobile: +46 708 909208 (+2h UTC) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] page() (Was: Re: predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall()))
On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > > > Here I think S3 dispatch is very natural. Try the following: > > I don't: it is documented to work on a name not an object. What comes first, the documentation of a method or the method itself? ;) I noticed the last year or so, that the documentation is being referred to as a requirement/design specification, in addition to being help pages. If this is in general true, that is a good guideline. Has this evolved recently, or is it just me that missed it before? /Henrik > > > page <- function(x, method = c("dput", "print"), ...) UseMethod("page") > > > > page.getAnywhere <- function(x, ..., idx=NULL) { > > name <- x$name; > > objects <- x$obj; > > > > if (length(objects) == 0) > >stop("no object named '", name, "' was found"); > > > > if (is.null(idx)) { > ># Include all non-duplicated objects found > >idx <- (1:length(objects))[!x$dups]; > > } > > > > for (ii in idx) { > >title <- paste(name, " (", x$where[ii], ")", sep=""); > >eval(substitute({ > > object <- x$obj[[ii]]; > > page(object, ...); > >}, list(object=as.name(title; > > } > > } > > > > page.default <- utils::page; > > > > page(getAnywhere("predict.smooth.spline.fit")) > > > > You can have page.function(), page.character(), page.environment(), > > etc. and make these call page.default() indirectly. What I think > > would be a very useful add on is to add an argument 'title' for which > > you can set/override the title. Then the "ugly" substitute() calls > > could be limited to one specific case; where a "default" object is > > passed and no title is set. > > > > If you want to, I could play around with a bit. > > > > /Henrik > > > > On 4/5/06, Kurt Hornik <[EMAIL PROTECTED]> wrote: > >>> Prof Brian Ripley writes: > >> > >>> On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > Hi, > > > > [snip] > > > >>> As for > >> > > PS, may I suggest to modify page() so that > > 'page(getAnywhere("predict.smooth.spline.fit"))' works? DS. > >> > >>> it is rather tricky. page() takes a name aka symbol as its argument > >>> (and is thereby S-compatible), and also works with a bare character > >>> string (undocumented). What you have here is a call that does not > >>> even return a function. It is more reasonable that > >>> stats:::predict.smooth.spline.fit should work, and it is also a call. > >>> I have in the past thought about special-casing that, but it is a > >>> valid name (you would have to back-quote it, but it does work). So > >>> one possible way out would be to use get() on a name and evaluate > >>> calls, e.g. > >> > >>> page <- function(x, method = c("dput", "print"), ...) > >>> { > >>> subx <- substitute(x) > >>> have_object <- FALSE > >>> if(is.call(subx)) { > >>> object <- x > >>> have_object <- TRUE > >>> subx <- deparse(subx) > >>> } else { > >>> if(is.character(x)) subx <- x > >>> else if(is.name(subx)) subx <- deparse(subx) > >>> if (!is.character(subx) || length(subx) != 1) > >>> stop("'page' requires a name, call or character string") > >>> parent <- parent.frame() > >>> if(exists(subx, envir = parent, inherits=TRUE)) { > >>> object <- get(subx, envir = parent, inherits=TRUE) > >>> have_object <- TRUE > >>> } > >>> } > >>> if(have_object) { > >>> method <- match.arg(method) > >>> file <- tempfile("Rpage.") > >>> if(method == "dput") > >>> dput(object, file) > >>> else { > >>> sink(file) > >>> print(object) > >>> sink() > >>> } > >>> file.show(file, title = subx, delete.file = TRUE, ...) > >>> } else > >>> stop(gettextf("no object named '%s' to show", subx), domain = NA) > >>> } > >> > >>> which also allows 1-element character vectors (and I am not entirely > >>> sure we want that). > >> > >> There was a similar issue with prompt() (actually, its default method) > >> for which I ended up "temporarily" providing the following (argh): > >> > >> else { > >> name <- substitute(object) > >> if (is.name(name)) > >> as.character(name) > >> else if (is.call(name) && (as.character(name[[1]]) %in% > >> c("::", ":::", "getAnywhere"))) { > >> name <- as.character(name) > >> name[length(name)] > >> } > >> else stop("cannot determine a usable name") > >> } > >> > >> Best > >> -k > >> > >> __ > >> 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 > > > > > > -- > Bria
[Rd] wishlist: 'formula' method for stripchart()
Folks, I would find it useful to have a formula method for stripchart() with 'data' and 'subset' arguments, similar to boxplot.formula() whose code can probably be adapted fairly easily. Comments? Peter Ehlers (Win XP) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
On Wed, 5 Apr 2006, Prof Brian Ripley wrote: > On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > >> On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: >>> On Wed, 5 Apr 2006, Henrik Bengtsson wrote: >>> Hi, forget about the below details. It is not related to the fact that the function is returned from a function. Sorry about that. I've been troubleshooting soo much I've been shoting over the target. Here is a much smaller reproducible example: x <- 1:10 y <- 1:10 + rnorm(length(x)) sp <- smooth.spline(x=x, y=y) ypred <- predict(sp$fit, x) # [1] 2.325181 2.756166 ... ypred2 <- predict(sp$fit, c(0,x)) # Error in Recall(object, xrange) : couldn't find # function "predict.smooth.spline.fit" >>> >>> It seems Recall is not searching (via findFun) from the right environment, >>> but at a quick glance it is not obvious to me why. >>> You can replace Recall by predict.smooth.spline.fit for now. >> >> More troubleshooting shows that by dispatching directly on 'sp' and >> not 'sp$fit' works. The reason that I do not want to do this is >> related to my questions yesterday that I want to keep the memory usage >> down and 'sp' hold quite some extra data even with keep.data=FALSE. > > Ahah! So you are not using this as intended, and I had not spotted this. > Now I understand: you are calling predict, which finds > predict.smooth.spline.fit via method registration, and dispatches it in > the environment used to call predict, .GlobalEnv, where of course it is > not visible. Then Recall uses that environment, but attempts to call the > method directly. > > If you call this as intended, predict is called from the body of > predict.smooth.spline where predict.smooth.spline.fit is visible. > > I am afraid that you should not be expecting to be able to subvert things > this way. > > [...] > > Now, I was a little surprised that Recall() needed to do a lookup, but R's > context only contains the name of the called function and not (a pointer > to) the function. I think the callfun field in the context is intended to contains this and was added with the intent of making things like sys.function more reliable but I'm not sure this was ever fully implemented. Might be worth checking into after 2.3 and modifying Recall to use it. luke -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: [EMAIL PROTECTED] Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
On Wed, 5 Apr 2006, Luke Tierney wrote: > On Wed, 5 Apr 2006, Prof Brian Ripley wrote: > >> [...] >> >> Now, I was a little surprised that Recall() needed to do a lookup, but R's >> context only contains the name of the called function and not (a pointer >> to) the function. > > I think the callfun field in the context is intended to contains this > and was added with the intent of making things like sys.function more > reliable but I'm not sure this was ever fully implemented. Might be > worth checking into after 2.3 and modifying Recall to use it. What 'callfun' field? It is not documented at the top of context.c ... silly me, believing the documentation! (Actually, the comment is quite economical about what is there.) It does seem applyClosure and R_execClosure set it, so this is worth doing. What's in callfun in other contexts seems odd (and R_GlobalEnv seems definitely wrong). tryDispatch has begincontext(&cntxt, CTXT_RETURN, call, rho, rho, pargs, R_NilValue);/ FIXME: put in op */ and there are some in the byte-code section. So it is probably safe to use callfun unless it is R_NilValue and otherwise search. As is, we have rather inconsistent behaviour. E.g., library(MASS) denumerate(~(1+2+3)^3 + a/b) works fine, as the denumerate methods are exported. However, in a new session do > MASS:::denumerate(~(1+2+3)^3 + a/b) Error in Recall(x[[2]]) : couldn't find function "denumerate.formula" whereas MASS:::denumerate.formula(~(1+2+3)^3 + a/b) works. (Why? The docs were wrong, and in that case the context contains the expression needed to get the function, not the name.) Thanks for the hint. Recall is used rarely, and it has been going wrong in quite a few cases (apart from Henrik's and that above I managed to generate examples in cophenetic.dendrogram and window.default), so I do wonder if we should not be fixing this for 2.3.0. Brian -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] wishlist: 'formula' method for stripchart()
On Wed, 5 Apr 2006, Peter Ehlers wrote: > Folks, > > I would find it useful to have a formula method for > stripchart() with 'data' and 'subset' arguments, similar > to boxplot.formula() whose code can probably be adapted > fairly easily. > > Comments? Are you offering to provide one? (Actually now is not a good time unless you have one in your back pocket as we are 5 days off feature freeze for 2.3.0.) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: >> On Wed, 5 Apr 2006, Henrik Bengtsson wrote: >> >>> On 4/5/06, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: On Wed, 5 Apr 2006, Henrik Bengtsson wrote: > Hi, > > forget about the below details. It is not related to the fact that > the function is returned from a function. Sorry about that. I've > been troubleshooting soo much I've been shoting over the target. Here > is a much smaller reproducible example: > > x <- 1:10 > y <- 1:10 + rnorm(length(x)) > sp <- smooth.spline(x=x, y=y) > ypred <- predict(sp$fit, x) > # [1] 2.325181 2.756166 ... > ypred2 <- predict(sp$fit, c(0,x)) > # Error in Recall(object, xrange) : couldn't find > # function "predict.smooth.spline.fit" It seems Recall is not searching (via findFun) from the right environment, but at a quick glance it is not obvious to me why. You can replace Recall by predict.smooth.spline.fit for now. >>> >>> More troubleshooting shows that by dispatching directly on 'sp' and >>> not 'sp$fit' works. The reason that I do not want to do this is >>> related to my questions yesterday that I want to keep the memory usage >>> down and 'sp' hold quite some extra data even with keep.data=FALSE. >> >> Ahah! So you are not using this as intended, and I had not spotted this. > > Neither did I ;) > >> Now I understand: you are calling predict, which finds >> predict.smooth.spline.fit via method registration, and dispatches it in >> the environment used to call predict, .GlobalEnv, where of course it is >> not visible. Then Recall uses that environment, but attempts to call the >> method directly. >> >> If you call this as intended, predict is called from the body of >> predict.smooth.spline where predict.smooth.spline.fit is visible. >> >> I am afraid that you should not be expecting to be able to subvert things >> this way. > > One could argue that it should not be possible to dispatch to a > non-exported method the way I did. If UseMethod() would use the same > search path as the calling expression in the parent frame (and not > from "within" the environment where the generic function lives), It *does* do the former: method dispatch is dynamically scoped. NB: 'via method registration'. > then the predict() would fail right away. However, I think it is a very > risky business to make such modifications to UseMethod(), because there > are probably unknown side effects to this. One could argue that the particular method should not have been registered, so it could only be found from within the namespace. However, there are several other examples (such as cophenetic.dendrogram) which are intended to work and fall foul of the same trap. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] uniroot warning (lack of) (PR#8750)
Full_Name: Chris Andrews Version: 2.2.1 OS: Windows Submission from: (NULL) (128.205.94.95) The function page for uniroot indicates If the algorithm does not converge in 'maxiter' steps, a warning is printed and the current approximation is returned. I have not been able to get a warning message even when I think I should get one (see code below). Perhaps the bug is in the .Internal(zeroin) or how the warning condition is detected (val[2] < 0) Perhaps (val[3]>tol) would work? Thanks, Chris # define a function with a root ff <- function(x) (x-pi)^3 # fail on a warning options(warn = 2) # find it uniroot(ff, c(-10,10)) # start to find it but maxiter is reached (with no warning) uniroot(ff, c(-10,10), maxiter=2) # OUTPUT: #$root #[1] -1.663169 # #$f.root #[1] -110.9215 # #$iter #[1] 2 # #$estim.prec #[1] 8.336831 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor2.1 year 2005 month12 day 20 svn rev 36812 language R > sessionInfo() R version 2.2.1, 2005-12-20, i386-pc-mingw32 attached base packages: [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base" __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] wishlist: 'formula' method for stripchart()
Sorry, I should have been clearer. This is definitely not a high-priority item and I hadn't intended it to be included for 2.3.0. Sure, I'll provide the code and help page adjustment. Peter Ehlers Prof Brian Ripley wrote: > On Wed, 5 Apr 2006, Peter Ehlers wrote: > >> Folks, >> >> I would find it useful to have a formula method for >> stripchart() with 'data' and 'subset' arguments, similar >> to boxplot.formula() whose code can probably be adapted >> fairly easily. >> >> Comments? > > > Are you offering to provide one? > > (Actually now is not a good time unless you have one in your back pocket > as we are 5 days off feature freeze for 2.3.0.) > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel