How to handle a private remote dependency in a new R package? - r

I am writing an R package (let's called it new.package) that needs to import functions from another private R package (let's called it remote.private.package). remote.private.package is a private package on a github private remote repository (let's assume at github::username/remote_private_package).
I have run the following line which adds a private remote dependency to the new.package DESCRIPTION file:
usethis::use_dev_package("remote.private.package", type = "Imports", remote = c("username/remote_private_package", auth_token = "my_github_auth_token"))
This is the content of the relevant section of the DESCRIPTION file, after running the above line:
...
Remotes:
username/remote_private_package,
my_github_auth_token
Imports:
remote.private.package (>= 0.1.0),
...
However when i run devtools::load_all() i get the following console message:
ℹ Loading new.package
ℹ The package `remote.private.package` (>= 0.1.0) is required.
✖ Would you like to install it?
1: Yes
2: No
Selection: 1
Error: HTTP error 404.
Not Found
Did you spell the repo owner (`username`) and repo name (`remote_private_package`) correctly?
- If spelling is correct, check that you have the required permissions to access the repo.
I am sure that the info is correct because when i run:
remotes::install_github("username/remote_private_package", auth_token = "my_github_auth_token")
library(remote.private.package)
The package is installed and loaded correctly.
What are the best practices to handle packages with private remote repository dependencies?

Related

Error "Unknown repository for package source: bitbucket" when deploying Shiny app [duplicate]

Summary
When creating a package, I can list CRAN dependencies in the Depends list in the DESCRIPTION file. This documentation outlines how to list Bitbucket dependencies, eg. Remotes: bitbucket::sulab/mygene.r#default.
However, I don't know how to do this when authentication is needed to access the repository.
Attempt
I've tried putting the following code into the main packagename.R file. The function contents work fine as a snippet at the top of a standalone script:
.onLoad <- function(libname, pkgname) {
otherPackageVersion <- "1.0"
if (suppressWarnings(suppressPackageStartupMessages(require("otherPackageName", quietly = TRUE, character.only = TRUE)))) {
if (installed.packages()[installed.packages()[,"Package"] == "otherPackageName", "Version"] != otherPackageVersion) {
remove.packages("otherPackage")
devtools::install_bitbucket(sprintf("bitbucketUser/otherPackageName#%s", otherPackageVersion), auth_token = Sys.getenv("BITBUCKET_PAT"))
}
} else {
devtools::install_bitbucket(sprintf("bitbucketUser/otherPackageName#%s", otherPackageVersion), auth_token = Sys.getenv("BITBUCKET_PAT"))
}
}
but R CMD check fails saying it cannot be loaded after hanging for a while:
checking whether package ‘packageName’ can be installed ... ERROR
Installation failed.
Further Detail
The version of devtools I have loaded is 1.12.0.9000 (see this Github thread) which I installed using devtools::install_github("hadley/devtools#1220"). This allows me to install private Bitbucket R packages using an App Password stored in an environment variable, rather than committing my username/password in plaintext.
This will not be possible until this (a pull request using Bitbucket PATs) is merged into the devtools package.
EDIT: Checking in on this many years later, it's sorted for me by the current version of devtools (2.4.3) using a BitBucket App Password with Repo Read/Write and Project Read/Write permissions.

Error installing miniconda on GitHub Actions in an R project

I am trying to build and deploy this bookdown project with GitHub Actions. One of the chapters uses the keras R package, which means I need to install Conda (or set up a virtual environment). At the end of the Miniconda installation command, there is an error when trying to collect metadata.
2020-06-24T04:47:59.7495480Z * Miniconda has been successfully installed at '/Users/runner/Library/r-miniconda'.
2020-06-24T04:47:59.7496060Z [1] "/Users/runner/Library/r-miniconda"
2020-06-24T04:48:00.3909040Z * Project '~/runners/2.263.0/work/drake/drake' loaded. [renv 0.10.0]
2020-06-24T04:48:00.7964920Z * The project and lockfile are out of sync -- use `renv::status()` for more details.
2020-06-24T04:48:00.7968340Z Warning message:
2020-06-24T04:48:00.7969190Z Project requested R version '3.6.0' but '4.0.1' is currently being used
2020-06-24T04:48:05.2408080Z Collecting package metadata (current_repodata.json): ...working... failed
2020-06-24T04:48:05.2410390Z
2020-06-24T04:48:05.2410820Z NotWritableError: The current user does not have write permissions to a required path.
2020-06-24T04:48:05.2411080Z path: /usr/local/miniconda/pkgs/cache/b89cf7bf.json
2020-06-24T04:48:05.2411230Z uid: 501
2020-06-24T04:48:05.2411350Z gid: 20
2020-06-24T04:48:05.2411430Z
2020-06-24T04:48:05.2411690Z If you feel that permissions on this path are set incorrectly, you can manually
2020-06-24T04:48:05.2411940Z change them by executing
2020-06-24T04:48:05.2412010Z
2020-06-24T04:48:05.2412260Z $ sudo chown 501:20 /usr/local/miniconda/pkgs/cache/b89cf7bf.json
2020-06-24T04:48:05.2412330Z
2020-06-24T04:48:05.2413470Z In general, it's not advisable to use 'sudo conda'.
2020-06-24T04:48:05.2413570Z
2020-06-24T04:48:05.2414250Z
2020-06-24T04:48:05.2886400Z ##[error]Error: Error 1 occurred creating conda environment r-reticulate
2020-06-24T04:48:05.2890770Z Execution halted
2020-06-24T04:48:05.3050700Z ##[error]Process completed with exit code 1.
The full job log is here.
Depending on how R is set up, this post might be helpful for you. You might need to configure the .Renviron file.
Unable to change python path in reticulate (R)

Private Bitbucket package dependency in R package

Summary
When creating a package, I can list CRAN dependencies in the Depends list in the DESCRIPTION file. This documentation outlines how to list Bitbucket dependencies, eg. Remotes: bitbucket::sulab/mygene.r#default.
However, I don't know how to do this when authentication is needed to access the repository.
Attempt
I've tried putting the following code into the main packagename.R file. The function contents work fine as a snippet at the top of a standalone script:
.onLoad <- function(libname, pkgname) {
otherPackageVersion <- "1.0"
if (suppressWarnings(suppressPackageStartupMessages(require("otherPackageName", quietly = TRUE, character.only = TRUE)))) {
if (installed.packages()[installed.packages()[,"Package"] == "otherPackageName", "Version"] != otherPackageVersion) {
remove.packages("otherPackage")
devtools::install_bitbucket(sprintf("bitbucketUser/otherPackageName#%s", otherPackageVersion), auth_token = Sys.getenv("BITBUCKET_PAT"))
}
} else {
devtools::install_bitbucket(sprintf("bitbucketUser/otherPackageName#%s", otherPackageVersion), auth_token = Sys.getenv("BITBUCKET_PAT"))
}
}
but R CMD check fails saying it cannot be loaded after hanging for a while:
checking whether package ‘packageName’ can be installed ... ERROR
Installation failed.
Further Detail
The version of devtools I have loaded is 1.12.0.9000 (see this Github thread) which I installed using devtools::install_github("hadley/devtools#1220"). This allows me to install private Bitbucket R packages using an App Password stored in an environment variable, rather than committing my username/password in plaintext.
This will not be possible until this (a pull request using Bitbucket PATs) is merged into the devtools package.
EDIT: Checking in on this many years later, it's sorted for me by the current version of devtools (2.4.3) using a BitBucket App Password with Repo Read/Write and Project Read/Write permissions.

Issue with R - Shiny command runGitHub() [duplicate]

I am trying to install a sample package from my github repo:
https://github.com/jpmarindiaz/samplepkg
I can install it when the repo is public using any of the following commands through the R interpreter:
install_github("jpmarindiaz/rdali")
install_github("rdali",user="jpmarindiaz")
install_github("jpmarindiaz/rdali",auth_user="jpmarindiaz")
But when the git repository is private I get an Error:
Installing github repo samplepkg/master from jpmarindiaz
Downloading samplepkg.zip from
https://github.com/jpmarindiaz/samplepkg/archive/master.zip
Error: client error: (406) Not Acceptable
I haven't figured out how the authentication works when the repo is private, any hints?
Have you tried setting a personal access token (PAT) and passing it along as the value of the auth_token argument of install_github()?
See ?install_github way down at the bottom (Package devtools version 1.5.0.99).
Create an access token in:
https://github.com/settings/tokens
Check the branch name and pass it to ref
devtools::install_github("user/repo"
,ref="main"
,auth_token = "tokenstring"
)
A more modern solution to this problem is to set your credentials in R using the usethis and credentials packages.
#set config
usethis::use_git_config(user.name = "YourName", user.email = "your#mail.com")
#Go to github page to generate token
usethis::create_github_token()
#paste your PAT into pop-up that follows...
credentials::set_github_pat()
#now remotes::install_github() will work
remotes::install_github("username/privaterepo")
More help at https://happygitwithr.com/common-remote-setups.html#common-remote-setups

OpenCPU cannot load Namespace 400 (Bad Request) Error in server mode

I've written a OpenCPU app package and have successfully tested it in single server mode. The server is setup and it can find the app no problem.
But it's erroring out on some of the ocpu calls with the following (from Chrome JS console):
POST http://mydomain/ocpu/library/userengagementdashboard/R/metricsList 400 (Bad Request) jquery-1.10.2.min.js:6
OpenCPU error HTTP 400
package or namespace load failed for 'userengagementdashboard'
In call:
NULL
Didn't get these errors in the single user server mode.
If I check on http://mydomain/ocpu/library/userengagementdashboard/NAMESPACE I get:
export(aggregatePlot)
export(clusterFun)
export(facetPlot)
export(facetsList)
export(getDataAll)
export(getDataFacet)
export(getDataTime)
export(getDataTimeFacet)
export(mergeClusters)
export(metricsList)
export(timeFacetPlot)
export(timePlot)
import(RDruid)
import(ggplot2)
import(lubridate)
import(parallel)
import(plyr)
import(reshape)
Is there a problem with my imports maybe?
UPDATE:
Solved this thanks to Jeroen's suggestion that I perhaps didn't have all the dependencies.
First I looked at the dependencies under http://mydomain/ocpu/library/ and installed any missing packages to the correct library location.
Then some of the imports and dependencies of these dependent packages had not been installed so I installed their dependencies as well. Problem solved!
Your package probably fails to load because some dependencies are not installed. This problem usually appears if the NAMESPACE file imports dependencies, which are not declared in the DESCRIPTION file. So if your NAMESPACE contains:
import(RDruid)
import(ggplot2)
import(lubridate)
import(parallel)
import(plyr)
import(reshape)
than your DESCRIPTION needs to contain a line:
Imports: Druid, ggplot2, lubridate, parallel, plyr, reshape
The R package manager looks at the DESCRIPTION to install dependencies when installing your package.

Resources