Skip to content

writing R extension

1 message · AA

AA
#
Thanks Barry,
I tested this solution and it works. Thanks also to Sarah Goslee for bringing up
alternative ideas. I guess I need to get into building proper packages now.
AA.

----- Original Message ----
From: Barry Rowlingson <b.rowlingson at lancaster.ac.uk>
Cc: r-help at stat.math.ethz.ch
Sent: Wednesday, December 20, 2006 12:31:09 PM
Subject: Re: [R] writing R extension
Sarah Goslee wrote:

            
Yikes No!

  That will load all the objects into the current workspace. If you save 
when you quit, you'll end up with umpteen copies of your package code!

  For simple bundles of functions, it would be better to use save() to 
save them all to a .RData-type file and then 'attach()' it. This way it 
doesn't get stuck in your workspace. So:

  > foo=function(x){x^2}
  > bar=function(y){y^6}
  > baz=function(z){z*3}

  > myFunctions=c("foo","bar","baz")
  > save(list=myFunctions,file="myFunctions.RData")

then quit R, start R in another workspace:

  > attach("/path/to/wherever/you/put/myFunctions.RData")
  > foo(2)
    [1] 4

  Building proper _packages_ (never call them 'libraries' - libraries 
are collections of packages) isn't that hard once you've done it a dozen 
times, although I'm starting the find the bondage and discipline of 
packaging R code getting to me.

Barry

______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.