1

I am running jobs remotely, and the cluster I am running it on does not have the R package I require. I have tried to install it using:

if(!require(hglm)){install.packages("hglm");require(hglm)}

and realise that I am required to select a CRAN mirror. I tried adding:

selectCRANmirror()

to the script, but received the error message, cannot select CRAN mirror non-interactively.

I then tried adding:

selectCRANmirror(ind=72)

as this is what I would use on my local computer to set the CRAN mirror to UK(St. Andrews), but this generates the error message:

Error in chooseCRANmirror(ind = 72) : unused argument(s) (ind = 72)

I was wondering if anyone could explain how to select the CRAN mirror on a remote device?

I amended my script to include the line suggested:

if(!require(hglm)){install.packages("hglm",repos="http://cran.us.r-project.org")

replacing with "http://star-www.st-andrews.ac.uk/cran" (St. Andrews mirror) and received the following message (I have included preceding scripts to help illuminate where the problem lies):

setwd("~/lustre2/s0784669")
load("df1QCMAF.RData")
.libPaths('~/RLibrary')
if(!require(GenABEL)){install.packages("GenABEL");require(GenABEL)}
#Loading required package: GenABEL
#Loading required package: MASS
#GenABEL v. 1.7-6 (May 16, 2013) loaded
if(!require(hglm)){install.packages("hglm",repos="http://star-www.st-andrews.ac.uk/cran");require(hglm)}
#Loading required package: hglm
#Installing package(s) into '/export/users/s0784669/RLibrary'
#(as 'lib' is unspecified)
#Warning: unable to access index for repository http://star-www.st-andrews.ac.uk/cran/src/contrib

I have tried:

library(RCurl)
url.exists("http://star-www.st-andrews.ac.uk/cran")

to ascertain internet access on the cluster and received the following message:

library(RCurl);
#Loading required package: bitops
url.exists("star-www.st-andrews.ac.uk/cran")
#[1] FALSE 

Suggesting no internet access. So would I have to access source code? And is this accessible?

GSee
  • 48,880
  • 13
  • 125
  • 145
Lynsey
  • 339
  • 1
  • 2
  • 11
  • possible duplicate of [How to select a CRAN mirror in R](http://stackoverflow.com/questions/11488174/how-to-select-a-cran-mirror-in-r) – Thomas Jul 29 '13 at 12:48
  • I've checked this out, and my problem is slightly different, because it is being run on a sun grid cluster, so I upload the whole script to one of the nodes and it goes through it start to finish, so I cannot interact with the computer once I have set the script running. – Lynsey Jul 29 '13 at 12:52
  • I tried the accepted answer, but it still would not run, see amended question. – Lynsey Jul 29 '13 at 12:58
  • Does the cluster have internet access? Try `library(RCurl); url.exists("http://star-www.st-andrews.ac.uk/cran")`. – Thomas Jul 29 '13 at 13:08
  • Error message: > library(RCurl); Loading required package: bitops > url.exists("http://star-www.st-andrews.ac.uk/cran") [1] FALSE Does this mean no internet access? – Lynsey Jul 29 '13 at 13:12
  • 1
    That's the error you get when R can't access the web, so probably. If you can retrieve the source from CRAN and send it to the cluster, [these answers](http://stackoverflow.com/questions/1474081/how-do-i-install-an-r-package-from-source) will be helpful for installing from local source. – Thomas Jul 29 '13 at 13:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34379/discussion-between-lynsey-hall-and-thomas) – Lynsey Jul 29 '13 at 13:14

2 Answers2

1

Per ?install.packages:

repos character vector, the base URL(s) of the repositories to use, e.g., the URL of a CRAN mirror such as "http://cran.us.r-project.org".

So do something like install.packages("hglm", repos="http://cran.us.r-project.org"). Insert the url to St Andrews instead.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • I tried this, but received the error message which I have added to my question above. Thank you for your reply. – Lynsey Jul 29 '13 at 13:07
0

I had the same question, then I tried this and it worked:

chooseCRANmirror(ind = 77)

With this code being put in front of any install.packages() statements, you can run the whole R script and successfully install packages non-interactively. Although it's been 7 years I hope this works for you and it could work for others!

Kenneth Z
  • 11
  • 1