rauthenticationgithubr-packager-usethis

How do I use the usethis package when I have already developed an R package on GitHub?


I have a package I created a while ago using the RStudio package option. I am linked in via 2 factor authentication. I have successfully pushed, pulled, and committed to my repo.

I have now reached the stage where I need to version my package. Section 22.1 on R packages 2e online says to use the use_release_issue in the usethis package. As this is a new package, I would like the release to be 1.0.

I am getting an error when I try to use the command. It seems to be related to the lack of a Personal Access Token for usethis. This is the first time I have used the usethis package.

The error I get is:

> usethis::use_release_issue("1.0")
✔ Setting active project to "[local file structure]PopulateR".
Error in `github_remotes()`:
✖ Unable to get GitHub info for these remotes: "origin".
ℹ Are we offline? Is GitHub down? Has the repo been deleted?
ℹ Otherwise, you probably need to configure a personal access token (PAT) for "github.com".
ℹ See usethis::gh_token_help() for advice.
Run `rlang::last_trace()` to see where the error occurred.

This is the last trace result:

Backtrace:
    ▆
 1. └─usethis::use_release_issue("1.0")
 2.   └─usethis:::target_repo(github_get = TRUE)
 3.     ├─cfg %||% github_remote_config(github_get = github_get)
 4.     └─usethis:::github_remote_config(github_get = github_get)
 5.       └─usethis:::github_remotes(github_get = github_get)
Run rlang::last_trace(drop = FALSE) to see 3 hidden frames.

If I create a PAT, will it cause me problems given it's an existing project already set up with a repo? It says that the PAT is for GitHub generally, rather than just for the project.

More specifically, will it cause me problems accessing the repo in the longer term?

I don't understand why I need a token at this point in development. Is there something I can configure that gets rid of the problem without requiring me to create a PAT?


Solution

  • TL;DR

    Simply follow the advice in usethis::gh_token_help() as it sets up a way to communicate with the GitHub API and won't effetc your project at all.

    Background

    The PAT (Personal Access Token) is a way to identify yourself against GitHub while using GitHub's API. The usethis library does some elaborate checks whether it can access the repo. In usethis:::github_remotes you will see that it tries to communicate with GitHub via the gh::gh function, which in turn is a slim client to consume the API.

    As said to use the API it needs a way to identify you and one way to do this is via the PAT. Thus, you should simply follow the advice to setup the PAT as it has nothing to do with your project at all, but is simply a way how to access GitHub via the API.