How do I install an R package from source?

后端 未结 6 687
半阙折子戏
半阙折子戏 2020-11-22 01:46

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 fro

相关标签:
6条回答
  • 2020-11-22 02:08

    In addition, you can build the binary package using the --binary option.

    R CMD build --binary RJSONIO_0.2-3.tar.gz
    
    0 讨论(0)
  • 2020-11-22 02:10

    You can install directly from the repository (note the type="source"):

    install.packages("RJSONIO", repos = "http://www.omegahat.org/R", type="source")
    
    0 讨论(0)
  • 2020-11-22 02:12

    From cran, you can install directly from a github repository address. So if you want the package at https://github.com/twitter/AnomalyDetection:

    library(devtools)
    install_github("twitter/AnomalyDetection")
    

    does the trick.

    0 讨论(0)
  • 2020-11-22 02:16

    Download the source package, open Terminal.app, navigate to the directory where you currently have the file, and then execute:

    R CMD INSTALL RJSONIO_0.2-3.tar.gz
    

    Do note that this will only succeed when either: a) the package does not need compilation or b) the needed system tools for compilation are present. See: https://cran.r-project.org/bin/macosx/tools/

    0 讨论(0)
  • 2020-11-22 02:28

    A supplementarily handy (but trivial) tip for installing older version of packages from source.

    First, if you call "install.packages", it always installs the latest package from repo. If you want to install the older version of packages, say for compatibility, you can call install.packages("url_to_source", repo=NULL, type="source"). For example:

    install.packages("http://cran.r-project.org/src/contrib/Archive/RNetLogo/RNetLogo_0.9-6.tar.gz", repo=NULL, type="source")
    

    Without manually downloading packages to the local disk and switching to the command line or installing from local disk, I found it is very convenient and simplify the call (one-step).

    Plus: you can use this trick with devtools library's dev_mode, in order to manage different versions of packages:

    Reference: doc devtools

    0 讨论(0)
  • 2020-11-22 02:30

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

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

    Where path_to_file would represent the full path and file name:

    • On Windows it will look something like this: "C:\\RJSONIO_0.2-3.tar.gz".
    • On UNIX it will look like this: "/home/blah/RJSONIO_0.2-3.tar.gz".
    0 讨论(0)
提交回复
热议问题