Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is not a valid installed package in R

Tags:

r

I'm a beginner with R (2 weeks at it), and am having a problem with something that should be simple: creating a package.

Just to get up and running, I've created a simple function:

square <- function(number)
{
answer <- number * number
return(answer)
}

Then I've set my working directory to where all of my other R packages are installed

setwd("/usr/local/lib/R/site-library")

Then I create a package

package.skeleton(list = c("square"), name = "sbpackage01") 

All files show up as expected in the new 'sbpackage01' directory, but when I open RCommander and try to use the package with

library(sbpackage01)

it tells me

'sbpackage01' is not a valid installed package

Any suggestions on what I'm missing? The next step in the tutorials I've seen is to compress then install it, but isn't the package installed by just doing 'package.skeleton...'?

Thanks for your help!

like image 712
MrX Avatar asked Jun 10 '13 16:06

MrX


1 Answers

something that should be simple: creating a package.

Haha. Well, no, creating a package in R isn’t quite simple (compared to module systems in other languages). You’re on the right track but before you can use your package you need to install it (or use devtools to install and load it dynamically).

The command package.skeleton actually creates a file Read-and-delete-me in your package directory which contains a short explanation of how to do this. Very briefly, you need to run the following command on the command line, from the parent directory of your package directory:

R CMD build packagename
R CMD INSTALL packagename

This is just a very brief explanation. Be sure to read one of the more detailed explanations, such as Friedrich Leisch’s Creating R Packages: A Tutorial [PDF].

like image 116
Konrad Rudolph Avatar answered Oct 04 '22 10:10

Konrad Rudolph