Installing a package offline from GitHub

前端 未结 5 1930
[愿得一人]
[愿得一人] 2020-12-14 18:06

I\'m trying to port some packages to an R installation on an offline (Windows) computer.

From CRAN (let\'s say data.table), the process: 1) download .zip

5条回答
  •  爱一瞬间的悲伤
    2020-12-14 19:04

    So I've finally come up with a workaround that works in some cases... but it's admittedly a bit macgyvered. Would love to hear some feedback about how to make this approach work for any package.

    Since I have a package where all of the code is in one .R file, I spoofed a package environment for that package and sourced the functions into that environment. Suppose the package is all in test.R:

    #add an appropriately named package to the search() path
    attach(environment(), name = "package:pkg")
    
    #source the functions
    sys.source("test.R", envir = as.environment("package:pkg"))
    

    Voila. I don't know enough about how packages are loaded to say how to do this, for example, if the package has src code in C or something else.

提交回复
热议问题