Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split project generating tools into a new repo generalized to start an R project in bcgov repo #10

Closed
boshek opened this issue Jun 27, 2017 · 9 comments
Assignees

Comments

@boshek
Copy link
Contributor

boshek commented Jun 27, 2017

  • This package currently accomplishes two things: provide a series of ggplot2 utilities and provide some tools to generate a repo in line with bcgov and environmental reporting requirement
  • Should we consider creating splitting these into two repos?
    - One repo could still contain the ggplot2 utilities
    - The other repo would be a "one stop shop if you are looking to set up a repository and project for R in the bcgov".
  • Using the tools that you've already created here, one could imagine a function like this:
start_project <- function(path = ".", git_init = TRUE,
                           rstudio = TRUE  ) {

  if (path != ".") dir.create(path, recursive = TRUE)

  npath <- normalizePath(path, winslash = "/", mustWork = TRUE)

  ## Need to check for analysis structure
  dirs <- file.path(npath, c("data", "graphics", "R","output"))

  Rfiles <- file.path(npath, c("set-up.R"))

  if (any(file.exists(dirs))) { ## file.exists is case-insensitive
    #if (git) unlink(c(".git", ".gitignore", recursive = TRUE, force = TRUE)
    stop("It looks as though you already have an analysis set up here!")
  }

  ## Add the necessary R files and directories
  message("Creating new analysis in ", npath)
  lapply(Rfiles, file.create)
  lapply(dirs, dir.create)

  if (rstudio) {
    if (!length(list.files(npath, pattern = "*.Rproj", ignore.case = TRUE))) {
      add_rproj(npath, paste0(basename(npath), ".Rproj"))
    } else {
      warning("Rproj file already exists, so not adding a new one")
    }
  }

  if (git_init) {
    if (file.exists(file.path(npath,".git"))) {
      warning("This directory is already a git repository. Not creating a new one")
    } else {
      git2r::init(npath)
    }
  }

  if (git_init) {
    write_gitignore(".Rproj.user", ".Rhistory", ".RData", "data/", "output/","graphics/",
                    "set-up.R", path = npath)
  }
  setwd(npath)
  message("Setting working directory to ", npath)
  invisible(npath)
}
  • This is adapted directly from the analysis_skeleton(). I'm not set on the name.
  • I have been using this rubric for setting up an analysis project though I am also not set on this approach. Just a start to the discussion.
  • I think that have a package=TRUE argument would make sense to set up along the lines or devtools::create and devtools::setup.
@stephhazlitt
Copy link
Member

stephhazlitt commented Jun 28, 2017

I think this is a good idea -- the bcgov-r-user package could also include some of the RStudio add-in functions currently in envreportutils which would be useful for any bcgov R/RStudio user (e.g. using Apache, BCDevEx badges - most of these yet to be added to the README). We would have to sit down and do some design work as some of the embedded arguments/options/functions are tailored for the EnvReportBC workflow.

@ateucher
Copy link
Contributor

💯 to the idea and @stephhazlitt comments.

As for analysis project templates, I like the idea of the main scripts being in the root directory (we tend to use number_name scripts so that it's obvious in what order they should be run (e.g., 01_load.R, 02_clean.R, 03_analysis.R, 04_output.R). I have started using the R/ folder for functions that I've written for the analysis - this seems to be pretty common convention and mirrors the structure of a package.

As mentioned in #9, I'd really like to use usethis to replace the backend of a lot of the infrastructure functions I wrote, but it's not on CRAN yet, so we'll have to continue to roll our own...

@ateucher
Copy link
Contributor

Let's start with a list of the exported functions and determine what package they belong in ('grover' or 'envreportutils').

Then we'll clone this repo into a new 'grover' repo, strip it down and modify to what we want in a general "R for bcgov" 📦.

Then we can strip down 'envreportutils' (working in a branch) to it's basics - it can always import 'grover' if it needs to.

@ateucher
Copy link
Contributor

ateucher commented Jul 14, 2017

Function Destination pkg Notes
add_code_of_conduct bcgovr
add_contributing bcgovr
add_license bcgovr
add_license_header bcgovr
add_readme bcgovr
add_rproj bcgovr
analysis_skeleton bcgovr
bgc_colours ??
devex_badge bcgovr
get_data_license envreportutils
multiplot envreportutils Eventually deprecate in favour of cowplot?
order_df ?? Eventually could be replaced by use of forcats::fct_reorder
roxygen_template Deprecate Replaced by RStudio shortcut : Ctrl+Alt+Shift+R
theme_soe envreportutils
theme_soe_facet envreportutils

@boshek
Copy link
Contributor Author

boshek commented Jul 14, 2017

That is basically what I've done over here:
https://github.com/bcgov/envreportutils/blob/grover_exp

The exports from the NAMESPACE file looks like this:

export(add_code_of_conduct)
export(add_contributing)
export(add_description)
export(add_license)
export(add_license_header)
export(add_readme)
export(add_rproj)
export(analysis_skeleton)
export(devex_badge)
export(get_data_license)
export(package_skeleton)
export(roxygen_template)

I've also added two new functions package_skeleton() and add_description(). I think they are sort self explanatory but I thought giving folks a head start with a DESCRIPTION template was a good idea.

@ateucher
Copy link
Contributor

I've moved the grover_exp branch to a new repo in bcgovr

@stephhazlitt
Copy link
Member

stephhazlitt commented Jul 19, 2017

Updating the list of functions for review now specific to envreportutils:

Function Destination pkg Notes
bgc_colours envreportutils
get_data_license envreportutils
multiplot envreportutils Eventually deprecate in favour of cowplot
order_df envreportutils Eventually could be replaced by use of forcats::fct_reorder
roxygen_template deprecate Replaced by RStudio shortcut : Ctrl+Alt+Shift+R
theme_soe envreportutils
theme_soe_facet envreportutils
envreportbc footer RStudio addin envreportutils

@ateucher
Copy link
Contributor

@stephhazlitt will take the lead on removing the functions that are moving to bcgovr

stephhazlitt added a commit that referenced this issue Jul 20, 2017
@stephhazlitt
Copy link
Member

Closed this with b2a2915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants