Skip to content
Prev 163404 / 398500 Next

selectively importing functions etc. from files

On Sun, 30 Nov 2008, Faheem Mitha wrote:

            
Right. And if you put all the objects in a package and do this:

## if you want to mask as little as possible, use
library(mypkg, pos = "package:base")

you will achieve this. You can also set

 	LazyLoad: yes

in the DESCRIPTION file. Then if you want to 'promote' functions to 
the .GlobalEnv, you can do

 	foo <- mypkg:::foo

Come to think of it, if the functions are all made local to the mypkg 
namespace, then they will only mask funcitons further down the search() 
list if they are called by other functions in mypkg.
Exactly. The objects that are not assign()ed or attach()ed will 
'disappear'.
OK. parse a file with two functions in it. Find one of the function 
expressions and evaluate it:
[1] "foobar.expr"
[1] 1
[1] "foo"         "foobar.expr"
function(x) x+1

---

Another way to achieve what you want is to put source of each function in 
its own file in a single directory. Then

 	source(file.path("pkgpath","foo.R"))

will load the single function in pkgpath/foo.R

HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901