Packages are the fundamental units of reproducible R code. They include reusable R functions, the documentation that describes how to use them, and sample data. You can find a thorough discussion of this topic in: R packages (2e) by Hadley Wickham and Jenny Bryan, available online at: https://r-pkgs.org/
This is what you need to build the package, not the packages that r4tcpl will need to run properly. Those are listed further down (see Package dependencies section).
-
If you are working on Windows, install the RTools version appropriate for the R release you are using.
-
Make sure
devtools
,roxygen2
,testthat
, andknitr
packages are already installed, otherwise install them running:install.packages(c("roxygen2", "testthat", "knitr", "devtools"))
.
-
Write/copy your function(s) into a .R file within
.../r4tcpl/R/
. -
Remember to include the
@export
tag in theroxygen
comments of all the functions you want to make visible whenr4tcpl
package will be loaded. When building the package, the correspondingexport()
statement will be automatically generated insideNAMESPACE
file. -
It’s important to note that
library()
should NEVER be used inside a package. Use instead the::
notation to explicitly refer specific namespaces. -
For each dependency (i.e., wherever you used the syntax
<package_name>::<object>
) remember to addpackage_name
toImports
field within theDESCRIPTION
file by typingusethis::use_package("package_name", min_version=TRUE)
from the project directory.../r4tcpl/
(set it as the working directory in RStudio). -
Unlike User Libraries, System Libraries don't need to be declared as dependencies (since they are expected to be always installed by default in every R distribution). However, whenever some function from a System Library other than The R Base Package (
base
) is used it is recommended to import it or the entire library in the package namespace by adding theroxygen
tags@importFrom
or@import
, respectively. When building the package, the correspondingimport()
statement will be automatically generated insideNAMESPACE
file. -
Add example data sets to the package running
usethis::use_data(<my_pkg_data>)
from the project directory. This command will save the data contained in the R variable<my_pkg_data>
to the folder.../r4tcpl/data/
as a binary.rda
representation (storing one R object in each .rda file). -
Remember to provide a complete documentation for both functions (by roxygen2 heading) and data (by editing the file
.../r4tcpl/R/data.R
), otherwise you will get a warning when building the package. -
From the project directory, run
devtools::document()
to convert roxygen comments into proper R documentation and (re)generateNAMESPACE
(based on@export
tags). Then you can usepkgload::dev_help('<function_name>')
to have a quick preview of the<function_name>.Rd
file. -
Possibly update tests in
.../r4tcpl/tests/testthat/test-data_exploration.R
. -
Possibly update the package version in the
DESCRIPTION
file -
From the project directory, run
devtools::check()
to build the package (remember that all@examples
will be used as tests in this phase; to prevent some of them from being run put them inside a\dontrun{}
section). -
Use
devtools::load_all()
to load the package from the local directory and possibly test the new features. -
When you are happy, you can
git add
,commit
, andpush
. -
Regardless of your wd, use
devtools::install_github("TCP-Lab/r4tcpl")
to install (or update) the package from GitHub, and load it as usual throughlibrary(r4tcpl)
.
The following packages need to be preinstalled before running
devtools::install_github("TCP-Lab/r4tcpl")
.
- GEOquery
- ggplot2
- svDialogs
- tools
- dplyr
- stringr
- AnnotationDbi
- VennDiagram
- futile.logger
- org.Hs.eg.db
- mclust
- Update the package name field in the
DESCRIPTION
file. - Update all package names in the
README
file. - Update the
.RProj
name. - Update the
.Rbuildignore
file. - Within the folders
.../r4tcpl/R/
and.../r4tcpl/tests/
look for mentions of the old package name within all .R files and update them. git add
,commit
, andpush
these changes to the old repository.- Delete the local repository folder.
- Go to GitHub and use the repository Settings to rename it.
git clone
locally the renamed repository.- From RStudio, run
devtools::document()
to update documentation (i.e., Rd files). - Run
devtools::check()
to build the renamed package. - If everything went fine,
git add
,commit
, andpush
some changes to the new repository as a final test. - Finally, remove your old package from R by
remove.packages("oldName")
... - ...and install the new one
devtools::install_github("TCP-Lab/newName")
If after devtools::install_github("TCP-Lab/r4tcpl")
you get this error
Using GitHub PAT from the git credential store.
Error: Failed to install 'r4tcpl' from GitHub:
HTTP error 401.
Bad credentials
you've got to find where the token is stored by running
Sys.getenv("GITHUB_TOKEN")
Sys.getenv("GITHUB_PAT")
gitcreds::gitcreds_get()
gitcreds::gitcreds_get()$password
and then remove it through, e.g., gitcreds::gitcreds_delete()
, as per
this thread.