1

For a corporate environment, I want our R users to use our local repository only. I have made corresponding required changes to Rprofile.site, .Rprofile, and repositories files as suggested by other posts and it works fine for changing the repository option only to the local one. However, a user is still able to select a CRAN mirror by selecting "Set CRAN Mirror" from the menu or by running "chooseCRANmirror()" command and when she does either of these, it will add standard CRAN repository as a repository option again. What can I do so that users don't see/get the default options for CRAN mirrors and as a result can no way change the local repository?

EDIT: As @Dason says, I don't want to stop the expert user from changing the repository option or others. I want to disable choosing mirrors just to ensure that users will not be able to access remote repositories (and download a package from there) by mistake.

kaisernahid
  • 341
  • 2
  • 13
  • 1
    Are you going to take away the ability to install packages locally from a file as well? – Dason Aug 20 '13 at 22:57
  • 1
    And what if they just manually change the 'repos' option? – Dason Aug 20 '13 at 23:01
  • No, I am not. The selected packages are stored in the local repository and I can have a mirror pointing to my local repository. Users can choose this local repository to install packages. – kaisernahid Aug 20 '13 at 23:02
  • 1
    So you don't want to lock them down from having the ability to install from CRAN? You just don't want them to be able to be able to use those two options to change the mirror? – Dason Aug 20 '13 at 23:05
  • 1
    That's a good question what if they manually change the 'repos' option. But that can only be done by an expert user. I just want to make sure users will not select unauthorized packages from other repositories by mistake. – kaisernahid Aug 20 '13 at 23:07
  • 2
    You could remmove or modify the `R_HOME/doc/CRAN_mirrors.csv` and `R_HOME/etc/repositories` files. – G. Grothendieck Aug 20 '13 at 23:20
  • Still wouldn't be able to stop a determined user but that sounds like what they want to do. – Dason Aug 20 '13 at 23:21
  • 1
    @G.Grothendieck, as the manual says, "A list of mirrors is stored in file ‘R_HOME/doc/CRAN_mirrors.csv’, but first an on-line list of current mirrors is consulted, and the file copy used only if the on-line list is inaccessible." and hence, modifying the csv file will not help. I have already modified the etc/repositories file but chooseCRANmirror() will override the repositories. – kaisernahid Aug 20 '13 at 23:25
  • 2
    You could modify `chooseCRANmirror` to pass `local.only = TRUE` – G. Grothendieck Aug 20 '13 at 23:40
  • Thanks @G.Grothendieck. I have also found out this just now. In order to pass local.only = TRUE, do I have to change the source code or changing some environment settings will do the work? – kaisernahid Aug 20 '13 at 23:51
  • Try: `trace("getCRANmirrors", quote(local.only <- TRUE))` – G. Grothendieck Aug 21 '13 at 00:05
  • @G.Grothendieck, users will be able to Set CRAN Mirror from the menu, so trace("getCRANmirrors", quote(local.only <- TRUE)) is not applicable. I guess the only option is to change the source code for getCRANmirrors in R. – kaisernahid Aug 21 '13 at 07:18
  • Buyt that menu just calls `chooseCRANmirrors` which calls `getCRANmirrors` so it will still be intercepted. – G. Grothendieck Aug 21 '13 at 10:12

1 Answers1

0

Looks like in utils/R/packages.R source code, chooseCRANmirros() calls the function getCRANmirrors(all = FALSE, local.only = FALSE) and it does the following:

getCRANmirrors <- function(all = FALSE, local.only = FALSE)
{
    m <- NULL
    if(!local.only) {
        ## try to handle explicitly failure to connect to CRAN.
        con <- url("http://cran.r-project.org/CRAN_mirrors.csv")
        m <- try(open(con, "r"), silent = TRUE)
        if(!inherits(m, "try-error")) m <- try(read.csv(con, as.is = TRUE))
        close(con)
    }
    if(is.null(m) || inherits(m, "try-error"))
        m <- read.csv(file.path(R.home("doc"), "CRAN_mirrors.csv"),
                      as.is = TRUE)
    if(!all) m <- m[as.logical(m$OK), ]
    m
}

So, it has a hard-coded value for the CRAN url if local.only is FALSE. Hence, I guess we have to set local.only to TRUE and then change the local CRAN_mirrors.csv file.

kaisernahid
  • 341
  • 2
  • 13