[R] scope of variable/object ?

Gabor Grothendieck ggrothendieck at gmail.com
Fri Apr 28 02:56:28 CEST 2006


You probably need to contact the developer of pamr but
short of investigating it, a workaround might be to put a copy
of myd2 into the global environment since it likely will at
least look there, e.g. add this line to:

   assign("myd2", myd2, .GlobalEnv)

domat.

On 4/27/06, Tim Smith <tim_smith_666 at yahoo.com> wrote:
> Hi,
>
>  I must be missing something here...Essentially, a short piece of code works if it's standalone, but doesn't work if it's divided into two functions.
>
>  The code that works is:
>
>   ################### WORKS ###############
>
> library(pamr)
>
> set.seed(120)
> x <- matrix(rnorm(1000*20),ncol=20)
> y <- sample(c(1:4),size=20,replace=TRUE)
> mydata <- list(x=x,y=y)
> mytrain <-   pamr.train(mydata)
> new.scales <- pamr.adaptthresh(mytrain,ntries = 1)
>
>  ########################################
>
>  But if I split the lines into two functions, then I get an error message that reads :
>  'Error in pamr.train(data = myd2, threshold = threshold, threshold.scale = all.scales[i+ : object "myd2" not found.'
>
>  The code that doesn't work is:
>
>
> ################### DOESN'T WORK ############
> library(pamr)
>
> domat <- function(myd){
>      myd2 <- myd
>    mytrain <-   pamr.train(myd2)
>    new.scales <- pamr.adaptthresh(mytrain)
>  }
>  dom <- function(){
>     set.seed(120)
>     x <- matrix(rnorm(1000*20),ncol=20)
>     y <- sample(c(1:4),size=20,replace=TRUE)
>     myda <- list(x=x,y=y)
>     domat(myda)
> }
>  dom()
>
>  #########################################
>
>  Did I do something really goofy? How can I find out what's happening?
>
>  many thanks.
>
>
>
>
> ---------------------------------
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list