Connect R package project to GitHub repo

I am building my first R-package, and I am now in the process of trying to connect this package to a GitHub repo.

I have no experience with R-package development, git, or GitHub prior to this.

I have followed the excellent happygit guide by Jenny Bryan (https://happygitwithr.com/new-github-first.html), and have been successful with running the examples, and I can connect my test projects in Rstudio to my test repos on Github.

Here is where I am stuck (on the second day now... please help me...)

Chapter 15 ("New Project GitHub First") and Chapter 16 ("Existing Project GitHub Last"), both use projects that are initiated by:

File > New Project > Version Control > Git . In the “repository URL” paste the URL of your new GitHub

As I understand it, this creates a Version Control Project and not a package. Therefore, all options in the Rstudio build tab (e.g., "Clean and Build") are gone, and only "Configure Build Tools" remains. This means that while I can push/pull to the Repo, I can't work on the package.

I have tried to get around this by:

  • Manually copying all files from a working "Package Project" into the Version Control Project, but this didn't work. Rstudio still appears to "think" of the project as a version control project.

  • Setting all the options in the "Configure Build Tools" pane of my "Version Control Project" to be identical to the "Configure Build Tools" pane in my "Package Project," but the package build options are still missing.

I realize that there is likely no easy solution or answer to this, but I hope that I, in spite of my effort, have missed something obvious, or that you can point me to a guide that can walk me through this setup.

Many thanks in advance,

Hello, and congratulations on taking the package building path. It is not quite easy (as you already noticed) but rewarding all the same :slight_smile:

Note that having a repository connected to GitHub and having it recognized by RStudio as a package are two separate topics.

You seem to have the GitHub part settled. To have RStudio recognize your project as a package you need to specify the project build tools section of your Rproj file as Package - see attached screenshot.

Also note that there are a couple formal requirements for your package for R to recognize it as such - these are mainly a R directory with some source files and DESCRIPTION metadata file.

I suppose you will find Hadley's R packages book an interesting read (I did!)

1 Like

If you're creating a new package, you can select "Create a git repository" when starting it through RStudio's "New Project" wizard.

If you want to set up a git repository inside an existing package, that's also pretty easy. Open the package project in RStudio, go to the "Terminal" pane (Alt+Shift+T), and enter this command:

git init

Now there's a git repo in your package.

1 Like

Hi,

I think you may find this blog post helpful:
https://www.hvitfeldt.me/blog/usethis-workflow-for-package-development/

Which uses heavily the functions from the usethis package (also developed by Jenny Bryan and Hadley Wickham) to streamline package development:

2 Likes

You can also just create a new package as normal, and choose for it to have git. Github Desktop now has the option to take a local git to form a new repository on Github. I believe the steps are to add a local repository and then there is an option to push to Github and create anew repository there.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.