Search code examples
rjenkinsdevtools

R install.package() paramaterize download.file() with options()


I am running a Jenkins build and leveraging the r-base docker image.

I'm trying to install devtools I suspect that the Self-Signed certificates are my problem.

When I try to install the package.

install.packages("devtools", 
                 method = options("extra", " --insecure --user"))

I get the following error

 'arg' must be NULL or a character vector

How can setup package.install to ignore the certificates? From what I've read I need to parameterize the download.file() with options() for the method parameter in install.packages() but I cannot figure out how.

NOTE: I am not an R programmer, if this is something basic, I am happy to learn if there is an R tutorial on stuff like this somewhere.

What am I doing wrong with method = options(...) and how can I pass -k or --insecure to libcurl?


Solution

  • To download.file with method = "libcurl" and some extra options, pass those values in the respective arguments to the download file function.

    install.packages("devtools", method = "libcurl", extra = " --insecure --user")
    

    These options can be set with options(). The example below sets the method an other, extra, download file options. The previous settings are saved in old_opt.

    libcurl_opts <- list(
      download.file.method = "libcurl",
      download.file.extra = " --insecure --user"
    )
    
    old_opt <- options(libcurl_opts)
    

    Check to see it worked.

    getOption("download.file.method")
    #[1] "libcurl"
    

    Now reset when done.

    options(old_opt)
    getOption("download.file.method")
    #NULL