We are using the drat R package to set up the infrastructure for a mini R package repository.
The intent is to make it easy for R users to install LandSciTech R packages that are not on CRAN, and keep them up to date.
The easiest way to set yourself up to use this drat repository is to first install the drat package:
install.packages("drat")
Then add the LandSciTech drat repo to your list of repositories to install from:
drat::addRepo("LandSciTech")
Add the above line to your .Rprofile
file so that the LandSciTech drat repository is
available every time you run R. This discussion
of R startup processes is a good introduction if you have never edited your .Rprofile
before.
Now you can install a package from the LandSciTech repository with install.packages()
.
For example:
install.packages(NAME_OF_PACKAGE_TO_INSTALL)
On Github:
- Fork this LandSciTech drat repository.
On the command line:
-
Clone this repository to your machine and open the directory:
git clone https://github.com/[YOUR GITHUB USERNAME]/drat cd drat
-
Build the package that you want to add to the drat repository. This can be done on the command line or in R using
devtools
:a. Command-line: Move to the directory in which your package directory resides and replace mypkg with the name of your package. Either of these will build a file called
mykg_pkg.ver.tar.gz
one directory up from your package directory:R CMD build "mypackage"
b. R/Rstudio: In the console in your R package project:
devtools::build()
-
Open R, and use the
drat::insertPackage()
function to add the built package (tar.gz
file) to the drat repo:drat::insertPackage("mypackage_pkg.ver.tar.gz", "path/to/drat")
- If you are comfortable, you can add the argument
commit = TRUE
to the above function call and it will automatically commit the changes that add the package to thegh-pages
branch in the drat repository. Otherwise, go to step 4:
- If you are comfortable, you can add the argument
-
Visually verify that the package has been added in
src/contrib
, then add, commit, and push the changes. Once you are satisfied you have added your package and would like to submit it to the LandSciTech drat repository, create a pull request to merge your changes (i.e. the addition of a new package) back in the LandSciTech drat repository.
Removing a package from a drat repository is a multi-stage process whereby the source file of the package is removed, the drat repository index is updated and then the changes are committed and pushed.
-
The first step is to fork this LandSciTech drat repository.
-
There are many way to remove the source file. Here we are removing it with R. If you are in the top-level
drat
directory you can set the directory where the source files are along with the specific source file you'd like to remove. From there removing the file is easily accomplished:# Source directory pkgdir <- normalizePath("./src/contrib", winslash = "\\") # Filename of the package you would like to remove pkgname <- "FILENAME.tar.gz" # Remove the source file file.remove(file.path(pkgdir, pkgname))
-
Now that we have removed the file, we need to update our index so that the repository no longer looks for the removed package like this:
tools::write_PACKAGES(dir = pkgdir, type = "source")
-
After completing steps 1, 2 and 3, there should 4 changes in your repository: the package itself and the three PACKAGES files. Stage, commit and push those changes. If you are happy with the results, you can submit a pull request to the LandSciTech drat repository. Once accepted, your package should now be completely removed from the LandSciTech drat repository.
Under active development.
Please note this was copied from the bcgov drat repository since their README provides good advice.
Copyright 2017 Province of British Columbia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.