MadSeb
MadSeb

Reputation: 8254

R - setting up my own CRAN repository

I want to set up a local CRAN repository . I want to put just one package in this repository ( let's call it MyPackage ). The reason I'm doing this is that I want to share this package with people at my company. By the way - we all use Ubuntu Linux. I have already done this:

However, when I do this:

install.packages("MyPackage", repos = "127.0.0.1/R" ) 

it does not work ;

Warning: unable to access index for repository [ ]
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
  package ‘MyPackage’ is not available (for R version 2.13.1)

Can you guys guide me a bit and tell me what is the correct folder structure ? Thanks.

Upvotes: 10

Views: 5205

Answers (4)

Ted M.
Ted M.

Reputation: 392

I think the problem is revealed in this statement: "In the contrib folder I put ... the PACKAGES file."

The PACKAGES file is an index for the repository. You need to create that file after your package files are placed in the repository directory. Don't copy and paste the PACKAGES file from another repository.

If I were you, here's what I would do. First, add the following code to your .Rprofile for a local repository:

utils::setRepositories(ind = 0, addURLs = c(WORK = "127.0.0.1/R"))

Restart R after changing your .Rprofile.

ind = 0 will indicate that you only want the local repository. Additional repositories can be included in the addURLs = option and are comma separated within the character vector.

Then, create the repository index:

tools::write_PACKAGES("127.0.0.1/R/src/contrib", verbose = TRUE) 

After you do that, you should be able to generate a data frame that has a list of all the packages. For example, my_packages <- available.packages().

If you see packages in your repository data frame, then install using the following code:

install.packages("MyPackage")

For more information, please see here.

Upvotes: 0

korniichuk
korniichuk

Reputation: 600

The miniCRAN works good for me. There are few advantages to using miniCRAN to create the repository:

  • Security: Many R users are accustomed to downloading and installing new R packages at will, from CRAN or one of its mirror sites.
  • Easier offline installation: To install package to an offline server requires that you also download all package dependencies, Using miniCRAN makes it easier to get all dependencies in the correct format.
  • Improved version management: In a multiuser environment, there are good reasons to avoid unrestricted installation of multiple package versions on the server.
  • Use other R Package Indexes: You may wish to make packages available from public repositories other than CRAN, e.g. BioConductor, r-forge, OmegaHat, etc.
  • Prepare own R repo: You may wish to add custom in-house packages to your repository.

See intro:

  1. Using miniCRAN to create a local CRAN repository
  2. Create a local package repository using miniCRAN

Upvotes: 2

Dirk is no longer here
Dirk is no longer here

Reputation: 368509

See "Section 6.6 Setting up a package repository" of the R Admin manual.

Edit some three+ years later: We now have the drat package which automates creating a repository, and can use GitHub in a clever way to host it for you.

Upvotes: 13

Aaron - mostly inactive
Aaron - mostly inactive

Reputation: 37804

You might just need to specify the URL properly; http://127.0.0.1/R.

Also, make sure you can access that URL in your browser.

Upvotes: 5

Related Questions