Thursday, April 28, 2011

How do I install an R package from source?

A friend sent me along this great tutorial on webscraping NYtimes with R. I would really love to try it. However, the first step is to installed a package called RJSONIO from source.

I know R reasonable well, but I have no idea how to install a package from source.

I have a mac OSX, if that is meaningful.

From stackoverflow
  • If you have the file locally, then use install.packages() and set the repos=NULL:

    install.packages(file_name_and_path, repos = NULL, type="source")
    

    Where file_name_and_path would represent the full path and file name. On windows this will look something like this: "C:\RJSONIO_0.2-3.tar.gz". On unix this would look like this: "\usr\blah\RJSONIO_0.2-3.tar.gz".

    Marek : It looks like installing from a windows binary (under Windows so it won't work on Mac OS).
    Shane : Thanks. Just clarified my answer.
  • Download the source package, open Terminal.app and execute

    R CMD INSTALL RJSONIO_0.2-3.tar.gz
    
    Madjoro : I tried this and got an error: Madjoro-MacBook-Pro:~ Madjoro$ R CMD INSTALL RJSONIO_0.2-3.tar.gz Warning: invalid package ‘RJSONIO_0.2-3.tar.gz’ Error: ERROR: no packages specified
    rcs : You have to specify the correct path to the .tar.gz file and the XCode tools (http://developer.apple.com/TOOLS/Xcode/) are required.
    haridsv : Is there a way to build the binary .zip from the source?
    haridsv : Found the solution, you need to use --binary option.
  • You can install directly from the repository (note the type="source"):

    install.packages("RJSONIO", repos = "http://www.omegahat.org/R", type="source")
    
    Madjoro : I tried this and got an error: * Installing *source* package ‘RJSONIO’ ... ** libs ** arch - i386 sh: make: command not found ERROR: compilation failed for package ‘RJSONIO’ RMate stopped at line 3 * Removing ‘/Library/Frameworks/R.framework/Versions/2.9/Resources/library/RJSONIO’ The downloaded packages are in ‘/private/var/folders/Ey/EyzhYjoKESmsmsZ6K87PeU+++TI/-Tmp-/Rtmpe3C96p/downloaded_packages’ Updating HTML index of packages in '.Library' Warning message: In install.packages("RJSONIO", repos = "http://www.omegahat.org/R", : installation of package 'RJSONIO' had non-zero exit status
    Eduardo Leoni : Do you have the developer tools installed? They come in the Mac OS X installation dvd. Since this package has C code you will need a compiler to install it from source.
    Madjoro : I suspect I do not have the developer tools installed. Atleast, I don't remember installing them. Thanks!
    Dan Goldstein : If you are doing this on windows, you can get the developer tools from http://www.murdoch-sutherland.com/Rtools/ ... make sure when installing you check the box that says to update your path (may be a bit hard to read .... just checked the unchecked box that comes up)
  • In addition, you can build the binary package using the --binary option.

    R CMD build --binary RJSONIO_0.2-3.tar.gz
    

0 comments:

Post a Comment