Skip to content

Project Setup

Thomas Leo Scherer edited this page Dec 10, 2020 · 14 revisions

Once you have completed the workstation setup, you are ready to setup a project or join in on an existing project.

Create a project directory

In RStudio, in the top left select File -> New Project or in the top right select Project: (None) -> New Project. A New Project window should appear giving three options to set up a project. Select Version Control then select Git.

For Repository URL: paste in the project's Git website (ex. https://github.com/centerforpeaceandsecuritystudies/MSSLStyleGuide). The Project directory name: will automatically fill in with the repository name (in example's case, "MSSLStyleGuide"). For Create project as subdirectory of:, select your dropbox folder "github_private" (so entry may become "~/Dropbox (rex)/github_private").

Pull the existing project files

Project directory organization

Setting up a new project directory

In most cases you will be joining a package that is already setup, so after you pull all the folders and files will already be organized for you.

If you are setting up the package for the first time, there are a couple ways to set it up. The older way with the usethis package was preferred until it recently gave us trouble. Until we can figure it out, there is the RStudio terminal method.

Terminal method

  1. Create the new package on github and get it's URL

  2. In RStudio without a package open, navigate to the folder you want to create the new package folder in. You can use the files subpane to navigate and then use that subpane's pulldown More -> Set As Working Director.

  3. Create the package with `usethis::create_package("PackageName")

  4. Open that new package in RStudio.

  5. In the console subpane switch to the terminal tab and set the github url with the command: git remote add origin _github url_

usethis method

You can use the package usethis to make it easy.

  1. Create the repository on the github website. Be sure to mark it private.

  2. Open RStudio and create a project directory as described above.

  3. With the project open in RStudio, run the following. On the last command you will be asked if you want to overwrite the existing package; answer no.

install.packages("devtools")
install.packages("usethis")
library(usethis)
create_package(getwd())
  1. Run the rest of this code. If it asks if you want to overwrite, you can say yes.

Note that one command may say that it cannot find the file DESCRIPTION. If you open DESCRIPTION from RStudio, that line should then work.

install.packages("callr")
install.packages("testthat")
use_mit_license("My Name")
use_package("MASS", "Suggests")
use_roxygen_md()
use_rcpp()
use_revdep()
use_readme_md()
use_news_md()
use_test("my-test")
x <- 1
y <- 2
use_data(x, y)
dir.create(file.path(getwd(), "docs"))
dir.create(file.path(getwd(), "inst"))
dir.create(file.path(paste0(getwd(),"/inst"), "extdata"))
dir.create(file.path(getwd(), "paper"))
dir.create(file.path(paste0(getwd(),"/paper"), "figures"))

If you get an error regarding RTools being incompatible, see issue 21.

  1. Set up R file for imports

In the R folder, create an R file titled packagename. Edit the code below for your package:

#'
#' The icb package is amazing
#'
#' @section icb functions:
#' The icb functions ...
#'
#' @docType package
#' @name icb
#'
#' @importFrom magrittr %>%
NULL

Now when you run the documentation steps, items in the import list will be added to the NAMESPACE, and will be automatically attached on the loadall command.

Clone this wiki locally