How do I load a package without installing it in R?

I'll join in "the chorus" of suggesting you should really install the package.

That having been said, you can take a look at Hadley's devtools package, which will let you load packages into the workspace without dumping in your global workspace.

The package will have to be untar'd/unzipped and follow the standard R package structure.

In order for this to work, though, your users would have to have the devtools package installed, so ... I'm not sure that this is any type of win for you.


If you only need the code to be loaded without it being installed, take the raw R script and source it:

source(myScript.R)

If you have different functions, you can create an R script that just loads all the necessary source files. What I sometimes do when developing, is name all my functions F_some_function.R and my classes Class_some_function.R. This allows me to source a main file containing following code :

funcdir <- "C:/Some/Path"
files <- dir(funcdir)
srcfiles <- c(grep("^Class_",dir(funcdir),value=T),
              grep("^F_",dir(funcdir),value=T)
)

for( i in paste(funcdir,srcfiles,sep="/")) source(i)

If you present them with the tarred file, they can untar themselves using untar() before sourcing the main file.

But honestly, please use a package. You load everything in the global environment (or in a specified environment if you use local=T), but you lose all functionality of a package. Installing a package is no hassle, and removing neither.

If it's a matter of writing rights on the C drive (which is the only possible reason not to use a package that I met in my carreer), one can easily set another library location. R 2.12 actually does this by itself on Windows. See ?.libPaths()

Tags:

R