I have a local GitLab account with an R package that can be installed by:
devtools::install_git(
url = "http://my-gitlab/my-projects/package",
credentials = git2r::cred_user_pass("user", "pass")
)
When I run renv::init()
the package source is unknown. The getting started article does give details about how to setup functions to deal with private repos but I can't figure it out for GitLab when using devtools
and git2r::cred_user_pass
. I could store GIT_USER
and GIT_PASSWORD
in an .Renviron
file but I'm not sure how to force the init
function to user devtools::install_git
with those credentials. I did try but then I get an error:
fatal: could not read Username for 'http://my-gitlab': No such device or address
All the example options they provide use a GitLab token for authentication:
# use a named list directly
options(renv.auth = list(
MyPackage = list(GITHUB_PAT = "<pat>")
))
Perhaps there is a better way to install from a local GitLab repo that will work better with renv
?
When I run renv::init() the package source is unknown.
renv
infers a package's source based on its DESCRIPTION
file, which (for custom remotes) is usually annotated post-hoc by the install function itself. I suspect install_git()
is not annotating the package in one of the ways expected by renv
, and so renv
is unable to infer the package source.
You could try and confirm this by checking the DESCRIPTION
file; eg a quick way to dump its contents would be:
writeLines(readLines(system.file("DESCRIPTION", package = <package>)))
and check for fields like RemoteType: git
to see if the package source has indeed been annotated.
For what it's worth, it looks like devtools::install_git()
delegates to remotes::install_git()
, and default Git credentials can be set via the remotes.git_credentials
option. For example:
options(remotes.git_credentials = git2r::cred_user_pass("user", "pass"))
Ultimately though, renv
relies on the use of a private access token (accessed via the GITLAB_PAT
environment variable for GitLab) in order to authenticate with private repositories.
Are you able to successfully install the package using renv::install()
with GITLAB_PAT
set? For example:
Sys.setenv(GITLAB_PAT = <...>)
renv::install("gitlab::user/project")
This is the workflow I would recommend, and should also be supported by the remotes
/ devtools
packages out-of-the-box.
For anyone else having the same problem, this worked for me (see here ):
api
. Note: I'm not sure this has to be 'api' I didn't check all options but it worked for meSys.setenv(GITLAB_PAT = <...>)
options(renv.config.gitlab.host = "http://my-gitlab-server")
. Note: I had to include "http://" to get it working.renv::install("gitlab::project/package")
renv::install("gitlab@my-gitlab-server::project/package")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.