One-liners to set-up R projects

Principles

Setup: start_here()

Before using starters for the first time, run start_here().

This function checks different aspects of your setup (Git installation, gitconfig, GITHUB_PAT, DESCRIPTION default values, GitHub username guessing), that will help automatic steps later on. Most of these aspects are inspired from usethis setup article.

starters::start_here()
#> Checking GitHub account can be guessed...
#> ✔ Your GitHub username is maelle.
#> Checking git is installed...
#> ✔ git seems to be installed!
#> Checking gitconfig...
#> ✔ gitconfig is already set!
#> Checking GITHUB_PAT...
#> ✔ GITHUB_PAT is already set!
#> Checking default description values...
#> ✔ DESCRIPTION defaults are already set!
#> Checking build tools are available...
#> ✔ Build tools are available!
#> ✔ All set now!

For each aspect, if your setup needs improvements an informative error message will be thrown so you might be able to know how to proceed.

starters::start_here()
#> Checking GitHub account can be guessed...
#> ✔ Your GitHub username is maelle.
#> Checking git is installed...
#> ✔ git seems to be installed!
#> Checking gitconfig...
#> ✔ gitconfig is already set!
#> Checking GITHUB_PAT...
#> ● GITHUB_PAT not set yet. Use this code (copied to clipboard): usethis::browse_github_pat()
#>  Error: Set your GITHUB_PAT then run starters::start_here() again. 

RStudio

All the projects are created with an RStudio project, but you could use starters outside of RStudio.

For RStudio addins fans, \@jonmcalder made a nifty RStudio addin for setting up projects with starters.

Best practice: Git, GitHub, Continuous Integration

By default, starters functions encourage the combined use of Git, GitHub and Travis for version control, project sharing, continuous checks and deliveries.

You can opt out of git by setting the git argument of starters functions to FALSE, and of GitHub as well as Travis by setting the external_setup argument to NULL. See this section for more information about git and external setup options in starters.

When the project is created all the template aspects will be committed to source control, such that you could import the project into GitHub, or use the command line to push it to GitHub.

As all the projects are created with an RStudio project, you should be able to work with the source control aspects within RStudio. You can also use your preferred shell or GUI to interact with it.

Camel or snake?

All project-creating functions in starters have both a snake case name, and a lower camel case name (for historical reasons). E.g. create_basic_project() (snake case) used to be named createBasicProject() (lower camel case). One can use any of these names to call the functions.

Your own adventure

All feedback, bug reports and feature requests, are welcome. Furthermore, if you want to create your own project-creating functions, you could browse starters' source code for inspiration.

Basic projects and their extensions

Basic projects

A basic project created with create_basic_project() is the fundamental building block for various flavours of projects you might build with starters (analysis projects, training projects).

A basic project contains a minimal package structure to allow you an easy way to:

Test create_basic_project() via running the chunk below, that'll create a basic project in a temporary directory, with no dependency management package (to make it run fast), and nothing on GitHub/Travis. The code will also open the new project in a new RStudio session so you can browse files.

starters::create_basic_project(name = "cooldoggos",
                               title = "A project about dogs",
                               folder = tempdir(),
                               packagedeps = "none",
                               external_setup = NULL,
                               open = TRUE)

All basic projects contain:

├── DESCRIPTION
├── R
├── README.Rmd
├── README.md
└── cooldoggos.Rproj

Dependency management

A problem with programming using other people's code is that other people's code changes. This risks your results changing over time. To prevent this,

Git, GitHub, Travis

We take the opinion that your project should feature the following things by default but they can always be turned off by using the parameters in the creation of a project.

external_setup = list(
                     git_service = "GitHub",
                     login = gh::gh_whoami()$login,
                     private = FALSE,
                     protocol = "ssh",
                     ci_activation = "travis"
                               )

Let's dig into the different elements of the list.

Analysis projects

Analysis projects are projects where you perform some analysis and probably produce some outputs. The function create_analysis_project() aims to facilitate your analysis by setting up a best practices template project.

At the moment, this function will set up a basic project with some additional folders, by default:

Test create_analysis_project() via running the chunk below, that'll create an analysis project in a temporary directory, with no dependency management package (to make it run fast), and nothing on GitHub/Travis. The code will also open the new project in a new RStudio session so you can browse files.

starters::create_analysis_project(name = "verycooldoggos",
                               title = "A project about dogs",
                               folder = tempdir(),
                               packagedeps = "none",
                               external_setup = NULL,
                               open = TRUE)

Resulting directory tree:

├── DESCRIPTION
├── R
├── README.Rmd
├── README.md
├── analysis
├── data
├── outputs
└── verycooldoggos.Rproj

Travis

By default, ci_activation of external_setup is equal to "travis"; these projects' tic.R will knit the R Markdown files contained in analysis/ and deploy them to a gh-pages branch. Note that GitHub pages websites are public.

You can opt out of Travis CI via setting the ci_activation element of the external_setup argument to NULL, e.g.

starters::create_analysis_project(name = "verycooldoggos",
                               title = "A project about dogs",
                               folder = tempdir(),
                               packagedeps = "none",
                               external_setup = list(git_service = "GitHub", 
                                                    login = gh::gh_whoami()$login,
                                                    private = FALSE,
                                                    protocol = "ssh", 
                                                    ci_activation = NULL),
                              open = TRUE)

or even external_setup = NULL to opt out of GitHub as well.

Training projects

Training projects are projects where you need to produce materials for others and/or to produce slides. The function create_training_project() aims to facilitate your training projects by setting up a best practices template project.

At the moment, this function will set up a basic project with some additional folders, by default:

Test create_training_project() via running the chunk below, that'll create a training project in a temporary directory, with no dependency management package (to make it run fast), and nothing on GitHub/Travis. The code will also open the new project in a new RStudio session so you can browse files.

starters::create_training_project(name = "verynicedoggos",
                               title = "A project about dogs",
                               folder = tempdir(),
                               dirs = c("data", "handouts", "slides", "cat-pictures"),
                               packagedeps = "none",
                               external_setup = NULL,
                               open = TRUE)

Resulting directory tree:

├── DESCRIPTION
├── R
├── README.Rmd
├── README.md
├── cat-pictures
├── data
├── handouts
├── slides
└── verynicedoggos.Rproj

Travis

By default, ci_activation of external_setup is equal to "travis"; these projects' tic.R will knit the R Markdown files contained in handouts/ and slides/ and deploy them to a gh-pages branch. Note that GitHub pages websites are public.

You can opt out of Travis CI via setting the ci_activation element of the external_setup argument to NULL, e.g.

starters::create_training_project(name = "verycooldoggos",
                               title = "A project about dogs",
                               folder = tempdir(),
                               packagedeps = "none",
                               external_setup = list(git_service = "GitHub", 
                                                    login = gh::gh_whoami()$login,
                                                    private = FALSE,
                                                    protocol = "ssh", 
                                                    ci_activation = NULL),
                              open = TRUE)

or even external_setup = NULL to opt out of GitHub as well.

Packages used to document

If you make a handouts/ or slides/ directory (both of which are created with the defaults), we will add rmarkdown to the project's DESCRIPTION file.

You can specify an alternative package for your handouts via handoutEngine. At present, two additional package options are supported. The first is bookdown, and the second is tufte. If you select bookdown or tufte as the handoutEngine, the relevant package will be added to the DESCRIPTION file and the demo files for this handout format will be added to the handouts/ directory.

You can also specify an alternative package for your slides via slideEngine. The currently supported (most popular) package options are revealjs and xaringan. Note also that the default slideEngine option (rmarkdown) caters for a number of additional R Markdown presentation formats such as io_slides, slidy, and beamer since these formats do not have additional package dependencies (although in the case of beamer, you'll need to have TeX installed). If you are using RStudio, you can find R Markdown templates for these presentation formats by going to File -> New File -> R Markdown -> Presentation.

If the packrat argument is not supplied or is set to TRUE, we will update the packrat manifest so that the packages are available when you open the project.

Package projects

The function create_package_project() aims to facilitate your package development by setting up a best practices template project. All starters projects take advantage of R package building infrastructure, but create_package_project() is the function you'd use as an R package developer to create an R package (or a research compendium).

Test create_package_project() via running the chunk below, that'll create a package project in a temporary directory, nothing on GitHub/Travis, and will open the new project in a new RStudio session so you can browse files.

starters::create_package_project(name = "coolkittens",
                               title = "A project about baby cats",
                               folder = tempdir(),
                               external_setup = NULL,
                               open = TRUE)

Resulting directory tree:

├── CODE_OF_CONDUCT.md
├── DESCRIPTION
├── LICENSE
├── LICENSE.md
├── NAMESPACE
├── NEWS.md
├── R
│   └── coolkittens-package.R
├── README.Rmd
├── README.md
├── _pkgdown.yml
├── coolkittens.Rproj
├── tests
│   ├── testthat
│   │   └── test-sample.R
│   └── testthat.R
└── vignettes
    └── coolkittens.Rmd

Package projects contain

Continuous integration

External setup is controlled like for basic projects with a supplementary argument coverage, either NULL, "codecov" or "coveralls" to control which code coverage, if any, is to be used.

The tic.R of package projects will check the package, build the pkgdown website and deploy it to a gh-pages branch, compute a project health report (see get_project_health()) and deploy it to a project-health branch.

You can opt out of Travis CI via setting the ci_activation element of the external_setup argument to NULL, e.g.

starters::create_package_project(name = "verycooldoggos",
                               title = "A project about dogs",
                               folder = tempdir(),
                               external_setup = list(git_service = "GitHub", 
                                                    login = gh::gh_whoami()$login,
                                                    private = FALSE,
                                                    protocol = "ssh", 
                                                    ci_activation = NULL),
                              open = TRUE)

or even external_setup = NULL to opt out of GitHub as well.



stephlocke/pRojects documentation built on Jan. 7, 2020, 7:27 p.m.