R interface to the carbon budget model library based on CBM-CFS3 (https://github.com/cat-cfs/libcbm_py/tree/cbm_exn).
# install.packages("devtools")
# devtools::install_dev_deps()
devtools::install("~/GitHub/libcbmr") ## source package directory
# install.packages("remotes")
remotes::install_github("PredictiveEcology/libcbmr")
Users on NRCAN machines may need to configure the use of the NRCAN root certificate in order to resolve SSL issues accessing HTTPS sites from R and python.
- Open Firefox and go to any website with https, for example https://www.anaconda.com/.
- Click on the lock icon in the address bar to view the website's security certificate.
- In the "Connection Secure" window, click on "More Information" to open the "Page Info" window.
- In the "Page Info" window, click on the "Security" tab.
- Click on "View Certificate" to open the "Certificate Viewer" tab.
- Click on the "NRCAN-RootCA" tab.
- Scroll down to the "Miscellaneous" section and select download pem (cert).
- Save this file to a convenient location (make note of the full file path you use).
Use either of the approaches below (not both) to set the variable for all R sessions or system-wide.
Use usethis::edit_r_environ("user")
to edit your user's .Renviron
file.
Add the following (using the actual path to the certificate file):
REQUESTS_CA_BUNDLE='/path/to/NRCAN-RootCA'
Setting this system-wide will affect all programs, not just R.
- Press the Windows key and type "env" to search for the "Environment Variables" settings.
- Create a new environment variable for your user named
REQUESTS_CA_BUNDLE
and set its value to the full file path of the certificate you downloaded. - Click Apply and OK to apply the changes.
Use one of the installation methods below.
- Install using conda:
NOTE: the full installation path cannot contain spaces, e.g. in your Windows user name.
## install python
library(reticulate)
condaVersion <- tryCatch(conda_version(conda = "auto"),
error = function(e) NA_character_)
if (is.na(condaVersion)) {
reticulate::install_miniconda() ## full path cannot contain spaces!
conda_create("r-reticulate")
}
## install libcbm (python package)
library(libcbmr)
envname <- "r-reticulate" ## default used by reticulate
install_libcbm(method = "conda", envname = envname)
- Install using pyenv/pyenv-win:
## install python
library(reticulate)
# pypath <- install_python(version = "3.11:latest")
## instead of using reticulate to install python,
## install manually from https://www.python.org/downloads/
## make note of the install location
pypath <- Sys.which("python")
envname <- "r-reticulate" ## default used by reticulate
envpath <- reticulate:::virtualenv_path(envname)
if (!dir.exists(envpath)) {
dir.create(envpath, recursive = TRUE)
}
virtualenv_create(envname, pypath)
library(libcbmr)
install_libcbm(method = "virtualenv", envname = envname)
library(reticulate)
library(libcbmr)
py_use_env(envname)