The general rule of thumb is that R copies data only when it needs to (a
piece of data is being modified while another variable/symbol is using it).
So even though R has "pass by value" semantics, data is not being copied
when being passed into functions (though if the local version of the data
is modified within the function, that would trigger a copy.

New to 3.1, copying is also shallow whenever possible, so modifying parts
of a complex object won't require the entire object to be copied.

As for the package question, Julian is correct, Except perhaps in the most
corner of cases, the source function has no place in an R package. If you
want people to be able to redo your exact computations, a dynamic document
(see SWeave, knitr) is a better mechanism to do that, and if you want
people to be able to use pieces of analysis logic you developed themselves
then they need to be in functions that those people can call.

~G


On Wed, Apr 16, 2014 at 5:41 AM, Julian Gehring <julian.gehr...@embl.de>wrote:

> Hi Ushi,
>
> > Thanks for your reply. I spoke to the original author. He has some
> > concerns about wrapping everything into separate functions.
>
> How you design the functions is in the end up to you.  Generally, in an
> R package there should not be the need for calling 'source'.
>
>
> > We are dealing with very large R objects. Is there a way to pass
> > those objects by reference to avoid copies and to modify them inside the
> > function?
> >
> > Does R implement CopyOnWrite to avoid copies?
>
> The way that R deals with objects in memory cannot be easily generalized
> to my knowledge (at least I have trouble understanding in detail when
> data actually gets copied).  Basic R functionality has the tendency to
> copy data often.  Within Bioconductor, there are several solutions that
> focus on a more efficient usage of the resources.  What may be suited
> for you depends largely on what kind of data or its representation you
> are using.
>
> Best wishes
> Julian
>
> _______________________________________________
> Bioc-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>



-- 
Computational Biologist
Genentech Research

        [[alternative HTML version deleted]]

_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel

Reply via email to