[R] Suggestion on how to make permanent changes to a singleobject in a list?
Charilaos Skiadas
cskiadas at gmail.com
Fri Jan 4 07:13:48 CET 2008
On Jan 4, 2008, at 12:06 AM, Peter Waltman wrote:
>
>> fooStack[[1]] <- fooModifier(fooStack[[1]])
> I thought of this idea as well, and may go with it, if the Gabor's
> environments idea doesn't work
>
>> snip
>>
>> Peter, perhaps it would help if you gave us more context into why
>> you wanted this done, and perhaps then someone can suggest a more
>> natural approach. Perhaps there is a more "R" way to solve your
>> original problem.
> it's fairly simple, but basically, we have a "cluster" object
> (which is really just a list) that has several items in it, one of
> which is something that we call a colslice (basically, just several
> columns of expression matrices). In reality, this cluster is part
> of a larger "meta-cluster" for genes from several different organisms.
snip
>
> I'm writing a function that will be called by another which
> generates the clusters and clusterStack objects, and the inner
> function should return the results some calculations on the
> $colslice and $rowslice items.
>
> I just wanted to have the inner function to retrieve the row/col
> slices from a MySQL database in case they haven't been set.
>
> The other workaround is just to make sure that they're already set
> by the time the function is called, and have the function throw an
> error if they're not. In fact, that might be the better way to do
> it, to provide better "encapsulation".
>
> I just wanted to see if it was possible to have the inner function
> set these.
Ah, I think I see now, you wanted that function to have a side-
effect, i.e. it returns something else, but along the way alters that
object as well. So the above assignment won't quite work for you. But
as you indeed point out, it would be probably better to have
retrieved those in the previous step.
Why isn't the top function retrieving those in the first place,
before calling the inner function?
Alternatively, I would have your inner function return a list of the
results, along with two extra fields with the colslice/rowslice
values, and then it would be the top function's responsibility to
replace its colslice/rowslice values with these new ones.
Your objects however seem to have a rigid enough structure, that I
would consider using S4 classes for them. That would provide in my
opinion a better encapsulation. But of course S4 classes have a bit
more initial setup work to do, but it's not that complicated once you
get the hang of it, and it can help abstract away some of the stuff.
> Thanks for all the suggestions!
>
> Peter
Good luck!
Haris Skiadas
Department of Mathematics and Computer Science
Hanover College
More information about the R-help
mailing list