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

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

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.

failing to devtools::install_github() from an enterprise github account

I am trying to install an R package from an enterprise github account
devtools::install_github(
repo = "<owner>/<repo>",
host = "github.<org_name>.com/api/v3/",
auth_token = <my_github_pat>
)
I get this error message
Error: Failed to install '<repo>' from GitHub: HTTP error 404. Not Found Did you spell the repo owner ('<owner>') and repo name ('<repo>') correctly? - If spelling is correct, check that you have the required permissions to access the repo.
I have the correct spellings, and I think that I must have the required permissions because it's actually my repo: I can push and pull from the repo just fine. I am doing the install_github() as a test case so colleagues can install my package, but I can't make sense of this error message.
Literally just needed to drop the last "/" in the host string and this worked. SMH
devtools::install_github(
repo = "<owner>/<repo>",
host = "github.<org_name>.com/api/v3",
auth_token = <my_github_pat>
)

github repo created from Rstudio using 'https' but files not uploaded to github

I'm trying to use git from within RStudio to send my project to github. I'm using HTTPS authentication and with this, I can create repository(locally and remotely) and commit changes. However, when i check my github, only repository is created but my R files not found.
This is what i tried
library(usethis)
edit_r_environ()
GITHUB_PAT = 'xxxx...X' #restart R session
use_github(protocol = 'https', auth_token = Sys.getenv("GITHUB_PAT")) #created a protocol with Access
token generated from PAT
#Are title and description ok?
1: No way
2: Definitely
3: Absolutely not
#i typed 2 and entered
After the above code, repository was created on github but my R codes are missing. I wanted to use push in git connection but the push/pull was greyed out.
Am aware of other approaches but help using the usethis package in R would be apreciated

Installing a package from private GitLab server on Windows

I am struggling with installing a package from a GitLab repository on a Windows computer.
I found different hints but still have problems to install my package from GitLab. First of all, I generated a public and private key with puttygen.exe. The files need to be changed afterwards, I had to remove comments and stuff so they look like my the file on my Unix system. So now, both public and private key files have just a single line.
I tried to install my package via devtools::install_git which takes very long and I get the error message
Error: Failed to install 'unknown package' from Git:
Error in 'git2r_remote_ls': Failed to authenticate SSH session: Unable to send userauth-publickey request
And with devtools::install_gitlab I get a different error message and I somehow have the feeling, the link which gets generated doesn't fit to my GitLab server.
Error: Failed to install 'unknown package' from GitLab:
cannot open URL 'https://gitlab.rlp.net/api/v4/projects/madejung%2FMQqueue.git/repository/files/DESCRIPTION/raw?ref=master'
My complete code to test at the moment is
creds <- git2r::cred_ssh_key(publickey="~/.ssh/id_rsa_gitlab.pub",
privatekey="~/.ssh/id_rsa_gitlab")
devtools::install_git(
url='git#gitlab.rlp.net:madejung/MQqueue.git',
quiet=FALSE,
credentials=creds)
devtools::install_gitlab(
repo='madejung/MQqueue.git',
host='gitlab.rlp.net',
quiet=FALSE,
credentials=creds
)
My id_rsa_gitlab.pub file looks like this and is just a single line:
ssh-rsa AAAA....fiwbw== rsa-key-20200121
The id_rsa_gitlab file has just the code:
AAABA.....3WNSIAGE=
Update
On my Mac system it works as expected after installing the libssh2 library via homebrew and and recompiling git2r with install.packages("git2r", type = "source").
So the working code on my machine is:
creds <- git2r::cred_ssh_key(publickey="~/.ssh/id_rsa_gitlab.rlp.net.pub",
privatekey="~/.ssh/id_rsa_gitlab.rlp.net")
devtools::install_git(
url='git#gitlab.rlp.net:madejung/MQqueue.git',
quiet=FALSE,
credentials=creds
)
For some strange reason, the devtools::install_git call needs about a minute to fail in the end. I have no idea where the problem here is.
After struggling for almost a day, I found a solution I can live with...
I first created a PAT (Personal Access Token) in my gitlab account and granted full API access. For some reason the read_only access didn't worked and I am now tired to figure out what the problem is.
After this I had still problems to install my package and for some reason, the wininet setting for downloading doesn't work.
I used the command capabilities("libcurl") to check if libcurl is available on my windows, which was and tried to overwrite wininet to libcurl by using method='libcurl' in the install function. Somehow, this was not enough so I overwrote the options variable download.file.method directly.
options("download.file.method"='libcurl')
devtools::install_gitlab(
repo='madejung/MQqueue',
auth_token='Ho...SOMETHING...xugzb',
host='gitlab.rlp.net',
quiet=FALSE, force=TRUE
)

Regarding to the R and Github

I tried to create Github repository through entering the following command in the R console:
devtools::use_github("https://github.com/SimonFans/RP")
But it gives such kind of error:
Error in gh::gh("POST /user/repos", name = pkg$Package, description = gsub("\n", :
GitHub API error (401): 401 Unauthorized
Bad credentials
Does anyone knows how to solve that?
If you execute this command, a new GitHub repo will be created via the GitHub API, therefore you must provide a GitHub
personal access token (PAT) via the argument auth_token, which defaults to the value of the
GITHUB_PAT environment variable. Obtain a PAT from https://github.com/settings/tokens.
The "repo" scope is required which is one of the default scopes for a new PAT.
You don't have this variable set therefore you need to specify it explicitly in your call to function use_github.

Resources