Sourcing R script over HTTPS

前端 未结 6 1672
盖世英雄少女心
盖世英雄少女心 2020-11-30 05:52

Is there some way to source an R script from the web?

e.g. source(\'http://github.com/project/R/file.r\')

Reason: I currently have a project tha

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 06:29

    Yes, it is possible and worked for me right away.

    R> source("http://pastebin.com/raw.php?i=zdBYP5Ft")
    R> test()
    [1] "passed"
    

    Regarding the HTTPS part, it isn't supported by internal R code. However, R can use external utilities like wget or curl to fetch https:// URLs. One will need to write additional code to be able to source the files.

    Sample code might be like this:

    wget.and.source <- function(url) {
      fname <- tempfile()
      download.file(url, fname, method="wget")
      source(fname)
      unlink(fname)
    }
    

    There is a Windows-only solution too: start R with --internet2 commandline option. This will switch all the internet code in R to using IE, and consequently HTTPS will work.

提交回复
热议问题