R package development - LandSciTech/R-Resources Wiki

The primary resource for package development is the book R Packages. It includes information on everything you need to know to build a package (with functions, tests and vignettes), connect it to GitHub and release it. The following are notes on implementing this process and some additional extensions (eg a pkgdown website and GitHub actions)

Change a package name

https://www.njtierney.com/post/2017/10/27/change-pkg-name/

Set up GitHub Actions

Follow instructions here to set up an action that runs R CMD CHECK. I had to make a new GitHub Personal Access Token because the one I had did not have the workflow scope. And also needed to add the following in order to get sf to work on the Mac for the GitHub action Before - name: Query dependencies and after - uses: r-lib/actions/[email protected] I added

      - name: Install GDAL/ Mac OS
        if: runner.os == 'macOS'
        run: |
          brew install pkg-config
          brew install gdal proj geos

I also changed the event that triggers the check to on: workflow_dispatch which means it is only run manually because if we are doing development on the master branch it uses up the resources quickly. The other option is to use branches for development and trigger the action on pull requests.

Setting up package website with pkgdown

Use usethis::use_pkgdown_github_pages() to add a GitHub action to build the website based on documentation and vignettes whenever there is a push to the master branch which will keep it up to date. It uses a branch called gh-pages to do this so just don’t mess with that branch.

CRAN R CMD CHECK NOTES that have caused issues

You will get a NOTE that says “no visible binding for global variable” if you use dplyr because column names are not really objects. Need to add .data$ before each, see

This also happened for me when I had data that I wanted to be available inside functions and also to the user. You can make it available to users with use_data(dataset) but you need to refer to it in the package with package::dataset