[BioC] assigning phenoData via assign

Benilton Carvalho bcarvalh at jhsph.edu
Mon May 7 19:33:16 CEST 2007

Hi Martin and Morgan,

I'm just writing some scripts to automate a few things here.

My function takes an object name (say, 'foo') and a path.

So, it loads data stored in path does lots of computations and stores  
the results in 'foo'.

I have a helper function that builds the correct phenoData for 'foo'.  
So I wanted to modify 'foo' after the computations are done.

Something like:

myAutomator <- function(objName, path){
   load(paste(path, "theData.rda", sep="/"))
   assign(objName, functionThatTakesLongTime(data))
   ## here I'd like to modify phenoData
   save(list=objName, file=paste(objName, "rda", sep="."))

But I just realized that for this particular case, the best is to  
pass the updated phenoData to functionThatTakesLongTime.


On May 7, 2007, at 1:12 PM, Seth Falcon wrote:

> Hi Benilton,
> Benilton Carvalho <bcarvalh at jhsph.edu> writes:
>> I'm trying to set the phenoData slot using get() or something
>> similar, eg:
> First of all, you probably want to use phenoData(foo) <- updatedPheno,
> not direct slot access.
>> library(Biobase)
>> objName <- "sample.ExpressionSet"
>> data(list=objName)
>> pd <- phenoData(get(objName))
>> get(objName)@phenoData <- pd    ## this will fail
> Perhaps it would help if you gave some context of what it is you are
> trying to achieve.
> Conceptually, get() returns a copy of the object requested and it
> doesn't make sense to modify an anonymous copy.
> Any modification of an object results in a copy (there are exceptions,
> but let's ignore them for now).  But R is clever about when the copy
> is actually made (just assigning to a tmp var doesn't trigger a copy).
>> I could copy the object to a temporary one:
>> tmp <- get(objName)
>> tmp at phenoData <- pd
>> assign(objName, tmp)
>> rm(tmp)
>> how can I avoid this copy?
> I'm not sure you can, but maybe I'm not understanding what you really
> want to do.
> + seth
> -- 
> Seth Falcon | Computational Biology | Fred Hutchinson Cancer  
> Research Center
> http://bioconductor.org
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/ 
> gmane.science.biology.informatics.conductor

More information about the Bioconductor mailing list