├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── R ├── dataset.R ├── function.R ├── new_project.R └── template-package.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── analyses └── README.md ├── data-raw └── README.md ├── data └── README.md ├── docs ├── 404.html ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── Rplot001.png │ ├── exampledataset.html │ ├── examplefunction.html │ ├── index.html │ ├── new_project.html │ └── template-package.html ├── files.png ├── inst └── makefile │ └── makefile.R ├── man ├── exampledataset.Rd ├── examplefunction.Rd ├── new_project.Rd └── template-package.Rd ├── manuscript └── README.md └── tests ├── testthat.R └── testthat └── test_fake.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^data-raw$ 4 | ^analyses$ 5 | ^manuscript$ 6 | README.Rmd 7 | 8 | ^_pkgdown\.yml$ 9 | ^docs$ 10 | ^pkgdown$ 11 | ^\.github$ 12 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. 2 | # https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | pull_request: 9 | branches: 10 | - main 11 | - master 12 | 13 | name: R-CMD-check 14 | 15 | jobs: 16 | R-CMD-check: 17 | runs-on: macOS-latest 18 | env: 19 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 20 | steps: 21 | - uses: actions/checkout@v2 22 | - uses: r-lib/actions/setup-r@v1 23 | - name: Install dependencies 24 | run: | 25 | install.packages(c("remotes", "rcmdcheck")) 26 | remotes::install_deps(dependencies = TRUE) 27 | shell: Rscript {0} 28 | - name: Check 29 | run: | 30 | options(crayon.enabled = TRUE) 31 | rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error") 32 | shell: Rscript {0} 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | template.Rproj 5 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: template 2 | Title: Generic template for data analysis projects structured as R packages 3 | Version: 0.5.3 4 | Authors@R: c( 5 | person("Francisco", "Rodriguez-Sanchez", , "f.rodriguez.sanc@gmail.com", role = c("aut", "cre"), 6 | comment = c(ORCID = "0000-0002-7981-1599")) 7 | ) 8 | Description: This package works as a template for new research or data analysis 9 | projects, under the idea of having everything (data, R scripts, functions 10 | and manuscript/reports) contained in the same package (a 'research compendium') 11 | to facilitate collaboration and promote reproducibility. 12 | Depends: 13 | R (>= 3.0.0) 14 | License: CC0 15 | LazyData: true 16 | URL: https://github.com/Pakillo/template 17 | BugReports: https://github.com/Pakillo/template/issues 18 | Imports: 19 | usethis, 20 | rstudioapi 21 | Suggests: 22 | testthat 23 | RoxygenNote: 7.1.1 24 | Encoding: UTF-8 25 | 26 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(examplefunction) 4 | export(new_project) 5 | -------------------------------------------------------------------------------- /R/dataset.R: -------------------------------------------------------------------------------- 1 | #' How to document datasets. 2 | #' 3 | #' This is an example showing how to document datasets included in the package (in \code{data} folder): 4 | #' you must specify docType and name; do not forget NULL in the end. 5 | #' Can include other fields, like citation. 6 | #' See \url{http://r-pkgs.had.co.nz/data.html} for further explanations. 7 | #' 8 | #' @docType data 9 | #' @name exampledataset 10 | #' @format A numeric vector. 11 | #' @source This example modified from C. Boettiger's template package \url{https://github.com/cboettig/template}. 12 | #' @examples 13 | #' \dontrun{ 14 | #' data(exampledataset) 15 | #' str(exampledataset) 16 | #' } 17 | NULL 18 | -------------------------------------------------------------------------------- /R/function.R: -------------------------------------------------------------------------------- 1 | #' How to document functions. 2 | #' 3 | #' This is an example showing how to document functions to be included in the package. 4 | #' 5 | #' @export 6 | #' @name examplefunction 7 | #' @author Francisco Rodriguez-Sanchez 8 | #' @param text Message to print. 9 | #' @seealso \url{http://r-pkgs.had.co.nz/man.html} 10 | #' @examples 11 | #' examplefunction('Hello world!') 12 | 13 | examplefunction <- function(text){ 14 | return(text) 15 | } 16 | -------------------------------------------------------------------------------- /R/new_project.R: -------------------------------------------------------------------------------- 1 | 2 | #' Create new project scaffolding 3 | #' 4 | #' Create all the scaffolding for a new project in a new directory. The scaffolding includes a README file, different folders to hold raw data, analyses, etc, and optionally also \code{testthat} infrastructure. Also, optionally, set a private or public GitHub repo with continuous integration (Travis-CI, GitHub Actions...). 5 | #' 6 | #' @param name Character. Name of the new project. A new folder will be created with that name. 7 | #' @param path Character. Path where the new project should be created (default is the current working directory). 8 | #' @param package Logical. Create package structure or a simple project? 9 | #' @param github Logical. Create GitHub repository? Note this requires some working infrastructure like \code{git} and a \code{GITHUB_PAT}. See instructions here \url{https://usethis.r-lib.org/articles/articles/usethis-setup.html}. 10 | #' @param private.repo Logical. Default is TRUE. 11 | #' @param ci Logical. Use continuous integration in your GitHub repository? Current options are "none" (default), "travis" (uses Travis-CI), "circle" (uses Circle-CI), "appveyor" (uses AppVeyor), or "gh-actions" (uses GitHub Actions). 12 | #' @param makefile Logical. If TRUE, adds a template \code{makefile.R} file to the project. 13 | #' @param pipe Logical. Use magrittr's pipe in your package? 14 | #' @param testthat Logical. Add testthat infrastructure? 15 | #' @param verbose Print verbose output in the console while creating the new project? Default is FALSE. 16 | #' @param open.project Logical. If TRUE (the default) will open the newly created Rstudio project in a new session. 17 | #' 18 | #' @return A new directory with R package structure, slightly modified. 19 | #' @export 20 | #' @details If using github = TRUE, you will be asked if you want to commit some files. Reply positively to continue. 21 | #' 22 | #' @examples 23 | #' \dontrun{ 24 | #' library("template") 25 | #' new_project("myproject") 26 | #' new_project("myproject", github = TRUE, private.repo = TRUE) 27 | #' } 28 | new_project <- function(name, path = ".", 29 | package = TRUE, 30 | github = FALSE, private.repo = TRUE, ci = "none", 31 | makefile = TRUE, pipe = TRUE, testthat = FALSE, 32 | verbose = FALSE, open.project = TRUE){ 33 | 34 | if (!isTRUE(verbose)) { 35 | options(usethis.quiet = TRUE) 36 | } 37 | 38 | if (isTRUE(package)) { 39 | usethis::create_package(file.path(path, name), open = FALSE) 40 | } else { 41 | usethis::create_project(file.path(path, name), open = FALSE) 42 | } 43 | 44 | # usethis::proj_set(name, force = TRUE) 45 | usethis::local_project(path = file.path(path, name), force = TRUE) 46 | 47 | # Add folders 48 | usethis::use_readme_rmd(open = FALSE) 49 | if (isTRUE(package)) { 50 | usethis::use_data_raw(open = FALSE) 51 | } else { 52 | dir.create("data-raw") 53 | } 54 | dir.create("data") 55 | dir.create("analyses") 56 | dir.create("manuscript") 57 | 58 | # Add makefile.R 59 | if (isTRUE(makefile)) { 60 | file.copy(from = system.file("makefile", "makefile.R", package = "template"), 61 | to = usethis::proj_get()) 62 | } 63 | 64 | 65 | if (isTRUE(package)) { 66 | 67 | usethis::use_package_doc(open = FALSE) 68 | 69 | if (isTRUE(pipe)) { 70 | usethis::use_pipe() 71 | } 72 | 73 | if (isTRUE(testthat)) { 74 | usethis::use_testthat() 75 | } 76 | 77 | usethis::use_build_ignore(c("analyses", "manuscript", "makefile.R")) 78 | 79 | } 80 | 81 | 82 | if (isTRUE(github)) { 83 | usethis::use_git() 84 | usethis::use_github(private = private.repo) 85 | # usethis::use_github_links(name) 86 | 87 | ## Continuous integration services 88 | stopifnot(ci %in% c("none", "travis", "gh-actions", "circle", "appveyor")) 89 | 90 | if (ci == "travis") { 91 | usethis::use_travis() 92 | #usethis::use_travis_badge() 93 | } 94 | 95 | if (ci == "gh-actions") { 96 | usethis::use_github_actions() 97 | # usethis::use_github_action_check_release() 98 | #usethis::use_github_actions_badge() 99 | } 100 | 101 | if (ci == "circle") { 102 | usethis::use_circleci() 103 | } 104 | 105 | if (ci == "appveyor") { 106 | usethis::use_appveyor() 107 | } 108 | 109 | } 110 | 111 | # Open Rstudio project in new session at the end? 112 | if (isTRUE(open.project)) { 113 | if (rstudioapi::isAvailable()) { 114 | rstudioapi::openProject(paste0(name, ".Rproj"), newSession = TRUE) 115 | } 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /R/template-package.R: -------------------------------------------------------------------------------- 1 | #' template package 2 | #' 3 | #' Generic template for research projects structured as R packages. 4 | #' This package works as a template for new research projects, 5 | #' under the idea of having everything (data, R scripts, functions and manuscripts) 6 | #' contained in the same package to promote reproducibility. 7 | #' 8 | #' @name template-package 9 | #' @docType package 10 | #' @author Francisco Rodriguez-Sanchez 11 | #' @keywords package 12 | #' @details For detailed steps on how to use the package see \url{https://github.com/Pakillo/template/blob/master/README.md}. 13 | #' 14 | NULL 15 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | ## `template` package 6 | 7 | ### Generic template for data analysis projects structured as R packages 8 | 9 | 10 | 11 | [![R-CMD-check](https://github.com/Pakillo/template/workflows/R-CMD-check/badge.svg)](https://github.com/Pakillo/template/actions) 12 | 13 | [![HitCount since 2020-06-14](http://hits.dwyl.com/Pakillo/template.svg)](http://hits.dwyl.com/Pakillo/template) 14 | 15 | 16 | 17 | The `template` package automates creation of new projects with all the necessary scaffolding: different folders for data, scripts, and functions, plus (optionally) additional files required for an R package structure. It can simultaneously create and synchronise a new repository on GitHub so one can start working immediately. 18 | 19 | `template` can create both projects with or without R package structure. Structuring data analysis projects as R packages (a.k.a. "research compendia") can bring some advantages (e.g. see [this blogpost](http://rmflight.github.io/post/analyses-as-packages/), [this repo](https://github.com/ropensci/rrrpkg), [these](https://inundata.org/talks/rstd19/#/) and [these slides](https://doi.org/10.6084/m9.figshare.12479984.v1) or read [Marwick et al.](https://doi.org/10.7287/peerj.preprints.3192v2)). But there are also [good reasons](https://milesmcbain.xyz/posts/an-okay-idea/) why an R package structure may not always be needed or convenient. 20 | 21 | 22 | ### Installation 23 | 24 | ```{r eval=FALSE} 25 | # install.packages("remotes") 26 | remotes::install_github("Pakillo/template") 27 | ``` 28 | 29 | 30 | ### Usage 31 | 32 | First, load the package: 33 | 34 | ```{r eval=FALSE} 35 | library("template") 36 | ``` 37 | 38 | Now run the function `new_project` to create a directory with all the scaffolding (slightly modified from R package structure). For example, to start a new project about tree growth, just use: 39 | 40 | ```{r eval=FALSE} 41 | new_project("treegrowth") 42 | ``` 43 | 44 | This will create a new Rstudio project with this structure: 45 | 46 | ```{r echo=FALSE} 47 | knitr::include_graphics("files.png") 48 | ``` 49 | 50 | You can create a GitHub repository for the project at the same time: 51 | 52 | ```{r eval=FALSE} 53 | new_project("treegrowth", github = TRUE, private.repo = FALSE) 54 | ``` 55 | 56 | You could choose either public or private repository. Note that to create a GitHub repo you will need to have configured your system as explained in https://usethis.r-lib.org/articles/articles/usethis-setup.html. 57 | 58 | There are other options you could choose, like setting up `testthat` or continuous integration (Travis-CI, GitHub Actions...). Or skip R package structure altogether. See `?new_project` for all options. 59 | 60 | 61 | ### Developing the project 62 | 63 | 1. Now edit `README.Rmd` and the `DESCRIPTION` file with some basic information about your project: title, brief description, licence, package dependencies, etc. 64 | 65 | 2. Place original (raw) data in `data-raw` folder. Save all R scripts (or Rmarkdown documents) used for data preparation in the same folder. 66 | 67 | 3. Save final (clean, tidy) datasets in the `data` folder. You may write [documentation](http://r-pkgs.had.co.nz/data.html#documenting-data) for these data. 68 | 69 | 4. R scripts or Rmarkdown documents used for data analyses may be placed at the `analyses` folder. The final manuscript/report may be placed at the `manuscript` folder. You could use one of the many Rmarkdown templates available out there (e.g. [rticles](https://github.com/rstudio/rticles), [rrtools](https://github.com/benmarwick/rrtools) or [rmdTemplates](https://github.com/Pakillo/rmdTemplates)). 70 | 71 | 5. If you write custom functions, place them in the `R` folder. [Document](http://r-pkgs.had.co.nz/man.html) all your functions with `Roxygen`. [Write tests](http://r-pkgs.had.co.nz/tests.html) for your functions and place them in the `tests` folder. 72 | 73 | 6. If your analysis uses functions from other CRAN packages, include these as dependencies (`Imports`) in the `DESCRIPTION` file (e.g. using `usethis::use_package()` or `rrtools::add_dependencies_to_description()`. Also, use `Roxygen` `@import` or `@importFrom` in your function definitions, or alternatively `package::function()`, to import these dependencies in the namespace. 74 | 75 | 7. I recommend using an advanced tool like [`targets`](https://github.com/wlandau/targets) to manage your project workflow. A simpler alternative might be writing a `makefile` or master script to organise and execute all parts of the analysis. A template makefile is included with this package (use `makefile = TRUE` when calling `new_project`). 76 | 77 | 8. Render Rmarkdown reports using `rmarkdown::render`, and use Rstudio `Build` menu to create/update documentation, run tests, build package, etc. 78 | 79 | 9. Record the exact dependencies of your project. One option is simply running `sessionInfo()` but many more sophisticated alternatives exist. For example, `automagic::make_deps_file()` or `renv::snapshot()` will create a file recording the exact versions of all packages used, which can be used to recreate such environment in the future or in another computer. If you want to use Docker, you could use e.g. `containerit::dockerfile()` or `rrtools::use_dockerfile()`. 80 | 81 | 10. Archive your repository (e.g. in Zenodo), get a DOI, and include citation information in your README. 82 | 83 | 84 | ### Thanks to: 85 | 86 | * Carl Boettiger and his [template package](https://github.com/cboettig/template) 87 | * Jeff Hollister and his [manuscriptPackage](https://github.com/jhollist/manuscriptPackage) 88 | * Robert Flight: http://rmflight.github.io/posts/2014/07/analyses_as_packages.html 89 | * Hadley Wickham: http://r-pkgs.had.co.nz/ 90 | * Yihui Xie: http://yihui.name/knitr/ 91 | * Rstudio 92 | 93 | 94 | ### Links 95 | 96 | * https://github.com/ropensci/rrrpkg 97 | * https://github.com/Reproducible-Science-Curriculum/rr-init 98 | * http://ropensci.github.io/reproducibility-guide/ 99 | * https://github.com/jdblischak/r-project-workflows 100 | * https://github.com/benmarwick/rrtools 101 | 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## `template` package 3 | 4 | ### Generic template for data analysis projects structured as R packages 5 | 6 | 7 | 8 | [![R-CMD-check](https://github.com/Pakillo/template/workflows/R-CMD-check/badge.svg)](https://github.com/Pakillo/template/actions) 9 | 10 | [![HitCount since 11 | 2020-06-14](http://hits.dwyl.com/Pakillo/template.svg)](http://hits.dwyl.com/Pakillo/template) 12 | 13 | 14 | The `template` package automates creation of new projects with all the 15 | necessary scaffolding: different folders for data, scripts, and 16 | functions, plus (optionally) additional files required for an R package 17 | structure. It can simultaneously create and synchronise a new repository 18 | on GitHub so one can start working immediately. 19 | 20 | `template` can create both projects with or without R package structure. 21 | Structuring data analysis projects as R packages (a.k.a. “research 22 | compendia”) can bring some advantages (e.g. see [this 23 | blogpost](http://rmflight.github.io/post/analyses-as-packages/), [this 24 | repo](https://github.com/ropensci/rrrpkg), 25 | [these](https://inundata.org/talks/rstd19/#/) and [these 26 | slides](https://doi.org/10.6084/m9.figshare.12479984.v1) or read 27 | [Marwick et al.](https://doi.org/10.7287/peerj.preprints.3192v2)). But 28 | there are also [good 29 | reasons](https://milesmcbain.xyz/posts/an-okay-idea/) why an R package 30 | structure may not always be needed or convenient. 31 | 32 | ### Installation 33 | 34 | ``` r 35 | # install.packages("remotes") 36 | remotes::install_github("Pakillo/template") 37 | ``` 38 | 39 | ### Usage 40 | 41 | First, load the package: 42 | 43 | ``` r 44 | library("template") 45 | ``` 46 | 47 | Now run the function `new_project` to create a directory with all the 48 | scaffolding (slightly modified from R package structure). For example, 49 | to start a new project about tree growth, just use: 50 | 51 | ``` r 52 | new_project("treegrowth") 53 | ``` 54 | 55 | This will create a new Rstudio project with this structure: 56 | 57 | 58 | 59 | You can create a GitHub repository for the project at the same time: 60 | 61 | ``` r 62 | new_project("treegrowth", github = TRUE, private.repo = FALSE) 63 | ``` 64 | 65 | You could choose either public or private repository. Note that to 66 | create a GitHub repo you will need to have configured your system as 67 | explained in 68 | . 69 | 70 | There are other options you could choose, like setting up `testthat` or 71 | continuous integration (Travis-CI, GitHub Actions…). Or skip R package 72 | structure altogether. See `?new_project` for all options. 73 | 74 | ### Developing the project 75 | 76 | 1. Now edit `README.Rmd` and the `DESCRIPTION` file with some basic 77 | information about your project: title, brief description, licence, 78 | package dependencies, etc. 79 | 80 | 2. Place original (raw) data in `data-raw` folder. Save all R scripts 81 | (or Rmarkdown documents) used for data preparation in the same 82 | folder. 83 | 84 | 3. Save final (clean, tidy) datasets in the `data` folder. You may 85 | write 86 | [documentation](http://r-pkgs.had.co.nz/data.html#documenting-data) 87 | for these data. 88 | 89 | 4. R scripts or Rmarkdown documents used for data analyses may be 90 | placed at the `analyses` folder. The final manuscript/report may be 91 | placed at the `manuscript` folder. You could use one of the many 92 | Rmarkdown templates available out there 93 | (e.g. [rticles](https://github.com/rstudio/rticles), 94 | [rrtools](https://github.com/benmarwick/rrtools) or 95 | [rmdTemplates](https://github.com/Pakillo/rmdTemplates)). 96 | 97 | 5. If you write custom functions, place them in the `R` folder. 98 | [Document](http://r-pkgs.had.co.nz/man.html) all your functions with 99 | `Roxygen`. [Write tests](http://r-pkgs.had.co.nz/tests.html) for 100 | your functions and place them in the `tests` folder. 101 | 102 | 6. If your analysis uses functions from other CRAN packages, include 103 | these as dependencies (`Imports`) in the `DESCRIPTION` file 104 | (e.g. using `usethis::use_package()` or 105 | `rrtools::add_dependencies_to_description()`. Also, use `Roxygen` 106 | `@import` or `@importFrom` in your function definitions, or 107 | alternatively `package::function()`, to import these dependencies in 108 | the namespace. 109 | 110 | 7. I recommend using an advanced tool like 111 | [`targets`](https://github.com/wlandau/targets) to manage your 112 | project workflow. A simpler alternative might be writing a 113 | `makefile` or master script to organise and execute all parts of the 114 | analysis. A template makefile is included with this package (use 115 | `makefile = TRUE` when calling `new_project`). 116 | 117 | 8. Render Rmarkdown reports using `rmarkdown::render`, and use Rstudio 118 | `Build` menu to create/update documentation, run tests, build 119 | package, etc. 120 | 121 | 9. Record the exact dependencies of your project. One option is simply 122 | running `sessionInfo()` but many more sophisticated alternatives 123 | exist. For example, `automagic::make_deps_file()` or 124 | `renv::snapshot()` will create a file recording the exact versions 125 | of all packages used, which can be used to recreate such environment 126 | in the future or in another computer. If you want to use Docker, you 127 | could use e.g. `containerit::dockerfile()` or 128 | `rrtools::use_dockerfile()`. 129 | 130 | 10. Archive your repository (e.g. in Zenodo), get a DOI, and include 131 | citation information in your README. 132 | 133 | ### Thanks to: 134 | 135 | - Carl Boettiger and his [template 136 | package](https://github.com/cboettig/template) 137 | - Jeff Hollister and his 138 | [manuscriptPackage](https://github.com/jhollist/manuscriptPackage) 139 | - Robert Flight: 140 | 141 | - Hadley Wickham: 142 | - Yihui Xie: 143 | - Rstudio 144 | 145 | ### Links 146 | 147 | - 148 | - 149 | - 150 | - 151 | - 152 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/template/349e5201c6952831e22fc346503d3ac4bb15ae40/_pkgdown.yml -------------------------------------------------------------------------------- /analyses/README.md: -------------------------------------------------------------------------------- 1 | Put here Rmarkdown documents involving different analyses for the project. 2 | -------------------------------------------------------------------------------- /data-raw/README.md: -------------------------------------------------------------------------------- 1 | Place here original (raw) data (e.g. in csv or txt format), together with R scripts used for data preparation. 2 | Clean data produced by those R scripts go to the `data` folder. 3 | -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | Put here clean, tidy data in R format (e.g. saved with `save` or `saveRDS` in R) or other formats (e.g. txt, csv). 2 | 3 | Write documentation for these data following the template in `R/dataset.R` (see http://r-pkgs.had.co.nz/data.html#documenting-data). 4 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • template 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
62 |
63 | 102 | 103 | 104 | 105 |
106 | 107 |
108 |
109 | 112 | 113 | Content not found. Please use links in the navbar. 114 | 115 |
116 | 117 | 122 | 123 |
124 | 125 | 126 | 127 |
128 | 131 | 132 |
133 |

Site built with pkgdown 1.6.1.

134 |
135 | 136 |
137 |
138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • template 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
62 |
63 | 102 | 103 | 104 | 105 |
106 | 107 |
108 |
109 | 112 | 113 |
    114 |
  • 115 |

    Francisco Rodriguez-Sanchez. Author, maintainer. 116 |

    117 |
  • 118 |
119 | 120 |
121 | 122 |
123 | 124 | 125 | 126 |
127 | 130 | 131 |
132 |

Site built with pkgdown 1.6.1.

133 |
134 | 135 |
136 |
137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.css: -------------------------------------------------------------------------------- 1 | /* Docsearch -------------------------------------------------------------- */ 2 | /* 3 | Source: https://github.com/algolia/docsearch/ 4 | License: MIT 5 | */ 6 | 7 | .algolia-autocomplete { 8 | display: block; 9 | -webkit-box-flex: 1; 10 | -ms-flex: 1; 11 | flex: 1 12 | } 13 | 14 | .algolia-autocomplete .ds-dropdown-menu { 15 | width: 100%; 16 | min-width: none; 17 | max-width: none; 18 | padding: .75rem 0; 19 | background-color: #fff; 20 | background-clip: padding-box; 21 | border: 1px solid rgba(0, 0, 0, .1); 22 | box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); 23 | } 24 | 25 | @media (min-width:768px) { 26 | .algolia-autocomplete .ds-dropdown-menu { 27 | width: 175% 28 | } 29 | } 30 | 31 | .algolia-autocomplete .ds-dropdown-menu::before { 32 | display: none 33 | } 34 | 35 | .algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { 36 | padding: 0; 37 | background-color: rgb(255,255,255); 38 | border: 0; 39 | max-height: 80vh; 40 | } 41 | 42 | .algolia-autocomplete .ds-dropdown-menu .ds-suggestions { 43 | margin-top: 0 44 | } 45 | 46 | .algolia-autocomplete .algolia-docsearch-suggestion { 47 | padding: 0; 48 | overflow: visible 49 | } 50 | 51 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 52 | padding: .125rem 1rem; 53 | margin-top: 0; 54 | font-size: 1.3em; 55 | font-weight: 500; 56 | color: #00008B; 57 | border-bottom: 0 58 | } 59 | 60 | .algolia-autocomplete .algolia-docsearch-suggestion--wrapper { 61 | float: none; 62 | padding-top: 0 63 | } 64 | 65 | .algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { 66 | float: none; 67 | width: auto; 68 | padding: 0; 69 | text-align: left 70 | } 71 | 72 | .algolia-autocomplete .algolia-docsearch-suggestion--content { 73 | float: none; 74 | width: auto; 75 | padding: 0 76 | } 77 | 78 | .algolia-autocomplete .algolia-docsearch-suggestion--content::before { 79 | display: none 80 | } 81 | 82 | .algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { 83 | padding-top: .75rem; 84 | margin-top: .75rem; 85 | border-top: 1px solid rgba(0, 0, 0, .1) 86 | } 87 | 88 | .algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { 89 | display: block; 90 | padding: .1rem 1rem; 91 | margin-bottom: 0.1; 92 | font-size: 1.0em; 93 | font-weight: 400 94 | /* display: none */ 95 | } 96 | 97 | .algolia-autocomplete .algolia-docsearch-suggestion--title { 98 | display: block; 99 | padding: .25rem 1rem; 100 | margin-bottom: 0; 101 | font-size: 0.9em; 102 | font-weight: 400 103 | } 104 | 105 | .algolia-autocomplete .algolia-docsearch-suggestion--text { 106 | padding: 0 1rem .5rem; 107 | margin-top: -.25rem; 108 | font-size: 0.8em; 109 | font-weight: 400; 110 | line-height: 1.25 111 | } 112 | 113 | .algolia-autocomplete .algolia-docsearch-footer { 114 | width: 110px; 115 | height: 20px; 116 | z-index: 3; 117 | margin-top: 10.66667px; 118 | float: right; 119 | font-size: 0; 120 | line-height: 0; 121 | } 122 | 123 | .algolia-autocomplete .algolia-docsearch-footer--logo { 124 | background-image: url("data:image/svg+xml;utf8,"); 125 | background-repeat: no-repeat; 126 | background-position: 50%; 127 | background-size: 100%; 128 | overflow: hidden; 129 | text-indent: -9000px; 130 | width: 100%; 131 | height: 100%; 132 | display: block; 133 | transform: translate(-8px); 134 | } 135 | 136 | .algolia-autocomplete .algolia-docsearch-suggestion--highlight { 137 | color: #FF8C00; 138 | background: rgba(232, 189, 54, 0.1) 139 | } 140 | 141 | 142 | .algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { 143 | box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) 144 | } 145 | 146 | .algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { 147 | background-color: rgba(192, 192, 192, .15) 148 | } 149 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Generic template for data analysis projects structured as R packages • template 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 23 | 24 | 25 |
    26 |
    66 | 67 | 68 | 69 | 70 |
    71 |
    72 |
    73 |

    74 | template package

    75 |
    76 |

    77 | Generic template for data analysis projects structured as R packages

    78 | 79 |

    The template package automates creation of new projects with all the necessary scaffolding: different folders for data, scripts, and functions, plus (optionally) additional files required for an R package structure. It can simultaneously create and synchronise a new repository on GitHub so one can start working immediately.

    80 |

    template can create both projects with or without R package structure. Structuring data analysis projects as R packages (a.k.a. “research compendia”) can bring some advantages (e.g. see this blogpost, this repo, these and these slides or read Marwick et al.). But there are also good reasons why an R package structure may not always be needed or convenient.

    81 |
    82 |
    83 |

    84 | Installation

    85 |
     86 | # install.packages("remotes")
     87 | remotes::install_github("Pakillo/template")
    88 |
    89 |
    90 |

    91 | Usage

    92 |

    First, load the package:

    93 | 95 |

    Now run the function new_project to create a directory with all the scaffolding (slightly modified from R package structure). For example, to start a new project about tree growth, just use:

    96 |
     97 | new_project("treegrowth")
    98 |

    This will create a new Rstudio project with this structure:

    99 |

    100 |

    You can create a GitHub repository for the project at the same time:

    101 |
    102 | new_project("treegrowth", github = TRUE, private.repo = FALSE)
    103 |

    You could choose either public or private repository. Note that to create a GitHub repo you will need to have configured your system as explained in https://usethis.r-lib.org/articles/articles/usethis-setup.html.

    104 |

    There are other options you could choose, like setting up testthat or continuous integration (Travis-CI, GitHub Actions…). Or skip R package structure altogether. See ?new_project for all options.

    105 |
    106 |
    107 |

    108 | Developing the project

    109 |
      110 |
    1. Now edit README.Rmd and the DESCRIPTION file with some basic information about your project: title, brief description, licence, package dependencies, etc.

    2. 111 |
    3. Place original (raw) data in data-raw folder. Save all R scripts (or Rmarkdown documents) used for data preparation in the same folder.

    4. 112 |
    5. Save final (clean, tidy) datasets in the data folder. You may write documentation for these data.

    6. 113 |
    7. R scripts or Rmarkdown documents used for data analyses may be placed at the analyses folder. The final manuscript/report may be placed at the manuscript folder. You could use one of the many Rmarkdown templates available out there (e.g. rticles, rrtools or rmdTemplates).

    8. 114 |
    9. If you write custom functions, place them in the R folder. Document all your functions with Roxygen. Write tests for your functions and place them in the tests folder.

    10. 115 |
    11. If your analysis uses functions from other CRAN packages, include these as dependencies (Imports) in the DESCRIPTION file (e.g. using usethis::use_package() or rrtools::add_dependencies_to_description(). Also, use Roxygen @import or @importFrom in your function definitions, or alternatively package::function(), to import these dependencies in the namespace.

    12. 116 |
    13. I recommend using an advanced tool like targets to manage your project workflow. A simpler alternative might be writing a makefile or master script to organise and execute all parts of the analysis. A template makefile is included with this package (use makefile = TRUE when calling new_project).

    14. 117 |
    15. Render Rmarkdown reports using rmarkdown::render, and use Rstudio Build menu to create/update documentation, run tests, build package, etc.

    16. 118 |
    17. Record the exact dependencies of your project. One option is simply running sessionInfo() but many more sophisticated alternatives exist. For example, automagic::make_deps_file() or renv::snapshot() will create a file recording the exact versions of all packages used, which can be used to recreate such environment in the future or in another computer. If you want to use Docker, you could use e.g. containerit::dockerfile() or rrtools::use_dockerfile().

    18. 119 |
    19. Archive your repository (e.g. in Zenodo), get a DOI, and include citation information in your README.

    20. 120 |
    121 |
    122 |
    123 |

    124 | Thanks to:

    125 | 138 |
    139 | 150 |
    151 |
    152 | 153 | 183 |
    184 | 185 | 186 |
    189 | 190 |
    191 |

    Site built with pkgdown 1.6.1.

    192 |
    193 | 194 |
    195 |
    196 | 197 | 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | img { 60 | max-width: 100%; 61 | } 62 | 63 | /* Fix bug in bootstrap (only seen in firefox) */ 64 | summary { 65 | display: list-item; 66 | } 67 | 68 | /* Typographic tweaking ---------------------------------*/ 69 | 70 | .contents .page-header { 71 | margin-top: calc(-60px + 1em); 72 | } 73 | 74 | dd { 75 | margin-left: 3em; 76 | } 77 | 78 | /* Section anchors ---------------------------------*/ 79 | 80 | a.anchor { 81 | margin-left: -30px; 82 | display:inline-block; 83 | width: 30px; 84 | height: 30px; 85 | visibility: hidden; 86 | 87 | background-image: url(./link.svg); 88 | background-repeat: no-repeat; 89 | background-size: 20px 20px; 90 | background-position: center center; 91 | } 92 | 93 | .hasAnchor:hover a.anchor { 94 | visibility: visible; 95 | } 96 | 97 | @media (max-width: 767px) { 98 | .hasAnchor:hover a.anchor { 99 | visibility: hidden; 100 | } 101 | } 102 | 103 | 104 | /* Fixes for fixed navbar --------------------------*/ 105 | 106 | .contents h1, .contents h2, .contents h3, .contents h4 { 107 | padding-top: 60px; 108 | margin-top: -40px; 109 | } 110 | 111 | /* Navbar submenu --------------------------*/ 112 | 113 | .dropdown-submenu { 114 | position: relative; 115 | } 116 | 117 | .dropdown-submenu>.dropdown-menu { 118 | top: 0; 119 | left: 100%; 120 | margin-top: -6px; 121 | margin-left: -1px; 122 | border-radius: 0 6px 6px 6px; 123 | } 124 | 125 | .dropdown-submenu:hover>.dropdown-menu { 126 | display: block; 127 | } 128 | 129 | .dropdown-submenu>a:after { 130 | display: block; 131 | content: " "; 132 | float: right; 133 | width: 0; 134 | height: 0; 135 | border-color: transparent; 136 | border-style: solid; 137 | border-width: 5px 0 5px 5px; 138 | border-left-color: #cccccc; 139 | margin-top: 5px; 140 | margin-right: -10px; 141 | } 142 | 143 | .dropdown-submenu:hover>a:after { 144 | border-left-color: #ffffff; 145 | } 146 | 147 | .dropdown-submenu.pull-left { 148 | float: none; 149 | } 150 | 151 | .dropdown-submenu.pull-left>.dropdown-menu { 152 | left: -100%; 153 | margin-left: 10px; 154 | border-radius: 6px 0 6px 6px; 155 | } 156 | 157 | /* Sidebar --------------------------*/ 158 | 159 | #pkgdown-sidebar { 160 | margin-top: 30px; 161 | position: -webkit-sticky; 162 | position: sticky; 163 | top: 70px; 164 | } 165 | 166 | #pkgdown-sidebar h2 { 167 | font-size: 1.5em; 168 | margin-top: 1em; 169 | } 170 | 171 | #pkgdown-sidebar h2:first-child { 172 | margin-top: 0; 173 | } 174 | 175 | #pkgdown-sidebar .list-unstyled li { 176 | margin-bottom: 0.5em; 177 | } 178 | 179 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 180 | 181 | /* All levels of nav */ 182 | 183 | nav[data-toggle='toc'] .nav > li > a { 184 | padding: 4px 20px 4px 6px; 185 | font-size: 1.5rem; 186 | font-weight: 400; 187 | color: inherit; 188 | } 189 | 190 | nav[data-toggle='toc'] .nav > li > a:hover, 191 | nav[data-toggle='toc'] .nav > li > a:focus { 192 | padding-left: 5px; 193 | color: inherit; 194 | border-left: 1px solid #878787; 195 | } 196 | 197 | nav[data-toggle='toc'] .nav > .active > a, 198 | nav[data-toggle='toc'] .nav > .active:hover > a, 199 | nav[data-toggle='toc'] .nav > .active:focus > a { 200 | padding-left: 5px; 201 | font-size: 1.5rem; 202 | font-weight: 400; 203 | color: inherit; 204 | border-left: 2px solid #878787; 205 | } 206 | 207 | /* Nav: second level (shown on .active) */ 208 | 209 | nav[data-toggle='toc'] .nav .nav { 210 | display: none; /* Hide by default, but at >768px, show it */ 211 | padding-bottom: 10px; 212 | } 213 | 214 | nav[data-toggle='toc'] .nav .nav > li > a { 215 | padding-left: 16px; 216 | font-size: 1.35rem; 217 | } 218 | 219 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 220 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 221 | padding-left: 15px; 222 | } 223 | 224 | nav[data-toggle='toc'] .nav .nav > .active > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 226 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 227 | padding-left: 15px; 228 | font-weight: 500; 229 | font-size: 1.35rem; 230 | } 231 | 232 | /* orcid ------------------------------------------------------------------- */ 233 | 234 | .orcid { 235 | font-size: 16px; 236 | color: #A6CE39; 237 | /* margins are required by official ORCID trademark and display guidelines */ 238 | margin-left:4px; 239 | margin-right:4px; 240 | vertical-align: middle; 241 | } 242 | 243 | /* Reference index & topics ----------------------------------------------- */ 244 | 245 | .ref-index th {font-weight: normal;} 246 | 247 | .ref-index td {vertical-align: top; min-width: 100px} 248 | .ref-index .icon {width: 40px;} 249 | .ref-index .alias {width: 40%;} 250 | .ref-index-icons .alias {width: calc(40% - 40px);} 251 | .ref-index .title {width: 60%;} 252 | 253 | .ref-arguments th {text-align: right; padding-right: 10px;} 254 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 255 | .ref-arguments .name {width: 20%;} 256 | .ref-arguments .desc {width: 80%;} 257 | 258 | /* Nice scrolling for wide elements --------------------------------------- */ 259 | 260 | table { 261 | display: block; 262 | overflow: auto; 263 | } 264 | 265 | /* Syntax highlighting ---------------------------------------------------- */ 266 | 267 | pre { 268 | word-wrap: normal; 269 | word-break: normal; 270 | border: 1px solid #eee; 271 | } 272 | 273 | pre, code { 274 | background-color: #f8f8f8; 275 | color: #333; 276 | } 277 | 278 | pre code { 279 | overflow: auto; 280 | word-wrap: normal; 281 | white-space: pre; 282 | } 283 | 284 | pre .img { 285 | margin: 5px 0; 286 | } 287 | 288 | pre .img img { 289 | background-color: #fff; 290 | display: block; 291 | height: auto; 292 | } 293 | 294 | code a, pre a { 295 | color: #375f84; 296 | } 297 | 298 | a.sourceLine:hover { 299 | text-decoration: none; 300 | } 301 | 302 | .fl {color: #1514b5;} 303 | .fu {color: #000000;} /* function */ 304 | .ch,.st {color: #036a07;} /* string */ 305 | .kw {color: #264D66;} /* keyword */ 306 | .co {color: #888888;} /* comment */ 307 | 308 | .message { color: black; font-weight: bolder;} 309 | .error { color: orange; font-weight: bolder;} 310 | .warning { color: #6A0366; font-weight: bolder;} 311 | 312 | /* Clipboard --------------------------*/ 313 | 314 | .hasCopyButton { 315 | position: relative; 316 | } 317 | 318 | .btn-copy-ex { 319 | position: absolute; 320 | right: 0; 321 | top: 0; 322 | visibility: hidden; 323 | } 324 | 325 | .hasCopyButton:hover button.btn-copy-ex { 326 | visibility: visible; 327 | } 328 | 329 | /* headroom.js ------------------------ */ 330 | 331 | .headroom { 332 | will-change: transform; 333 | transition: transform 200ms linear; 334 | } 335 | .headroom--pinned { 336 | transform: translateY(0%); 337 | } 338 | .headroom--unpinned { 339 | transform: translateY(-100%); 340 | } 341 | 342 | /* mark.js ----------------------------*/ 343 | 344 | mark { 345 | background-color: rgba(255, 255, 51, 0.5); 346 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 347 | padding: 1px; 348 | } 349 | 350 | /* vertical spacing after htmlwidgets */ 351 | .html-widget { 352 | margin-bottom: 10px; 353 | } 354 | 355 | /* fontawesome ------------------------ */ 356 | 357 | .fab { 358 | font-family: "Font Awesome 5 Brands" !important; 359 | } 360 | 361 | /* don't display links in code chunks when printing */ 362 | /* source: https://stackoverflow.com/a/10781533 */ 363 | @media print { 364 | code a:link:after, code a:visited:after { 365 | content: ""; 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent; 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.11.2 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: {} 5 | last_built: 2021-04-29T22:51Z 6 | 7 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/template/349e5201c6952831e22fc346503d3ac4bb15ae40/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/exampledataset.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | How to document datasets. — exampledataset • template 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
    66 |
    67 | 106 | 107 | 108 | 109 |
    110 | 111 |
    112 |
    113 | 118 | 119 |
    120 |

    This is an example showing how to document datasets included in the package (in data folder): 121 | you must specify docType and name; do not forget NULL in the end. 122 | Can include other fields, like citation. 123 | See http://r-pkgs.had.co.nz/data.html for further explanations.

    124 |
    125 | 126 | 127 | 128 |

    Format

    129 | 130 |

    A numeric vector.

    131 |

    Source

    132 | 133 |

    This example modified from C. Boettiger's template package https://github.com/cboettig/template.

    134 | 135 |

    Examples

    136 |
    if (FALSE) { 137 | data(exampledataset) 138 | str(exampledataset) 139 | } 140 |
    141 |
    142 | 147 |
    148 | 149 | 150 |
    151 | 154 | 155 |
    156 |

    Site built with pkgdown 1.6.1.

    157 |
    158 | 159 |
    160 |
    161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /docs/reference/examplefunction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | How to document functions. — examplefunction • template 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 103 | 104 | 105 | 106 |
    107 | 108 |
    109 |
    110 | 115 | 116 |
    117 |

    This is an example showing how to document functions to be included in the package.

    118 |
    119 | 120 |
    examplefunction(text)
    121 | 122 |

    Arguments

    123 | 124 | 125 | 126 | 127 | 128 | 129 |
    text

    Message to print.

    130 | 131 |

    See also

    132 | 133 | 134 |

    Author

    135 | 136 |

    Francisco Rodriguez-Sanchez

    137 | 138 |

    Examples

    139 |
    examplefunction('Hello world!') 140 |
    #> [1] "Hello world!"
    141 |
    142 | 147 |
    148 | 149 | 150 |
    151 | 154 | 155 |
    156 |

    Site built with pkgdown 1.6.1.

    157 |
    158 | 159 |
    160 |
    161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Function reference • template 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
    62 |
    63 | 102 | 103 | 104 | 105 |
    106 | 107 |
    108 |
    109 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 138 | 139 | 140 | 141 | 144 | 145 | 146 | 147 | 150 | 151 | 152 | 153 | 156 | 157 | 158 | 159 |
    124 |

    All functions

    125 |

    126 |
    136 |

    exampledataset

    137 |

    How to document datasets.

    142 |

    examplefunction()

    143 |

    How to document functions.

    148 |

    new_project()

    149 |

    Create new project scaffolding

    154 |

    template-package

    155 |

    template package

    160 |
    161 | 162 | 167 |
    168 | 169 | 170 |
    171 | 174 | 175 |
    176 |

    Site built with pkgdown 1.6.1.

    177 |
    178 | 179 |
    180 |
    181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /docs/reference/new_project.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Create new project scaffolding — new_project • template 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 103 | 104 | 105 | 106 |
    107 | 108 |
    109 |
    110 | 115 | 116 |
    117 |

    Create all the scaffolding for a new project in a new directory. The scaffolding includes a README file, different folders to hold raw data, analyses, etc, and optionally also testthat infrastructure. Also, optionally, set a private or public GitHub repo with continuous integration (Travis-CI, GitHub Actions...).

    118 |
    119 | 120 |
    new_project(
    121 |   name,
    122 |   path = ".",
    123 |   package = TRUE,
    124 |   github = FALSE,
    125 |   private.repo = TRUE,
    126 |   ci = "none",
    127 |   makefile = TRUE,
    128 |   pipe = TRUE,
    129 |   testthat = FALSE,
    130 |   verbose = FALSE,
    131 |   open.project = TRUE
    132 | )
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 |
    name

    Character. Name of the new project. A new folder will be created with that name.

    path

    Character. Path where the new project should be created (default is the current working directory).

    package

    Logical. Create package structure or a simple project?

    github

    Logical. Create GitHub repository? Note this requires some working infrastructure like git and a GITHUB_PAT. See instructions here https://usethis.r-lib.org/articles/articles/usethis-setup.html.

    private.repo

    Logical. Default is TRUE.

    ci

    Logical. Use continuous integration in your GitHub repository? Current options are "none" (default), "travis" (uses Travis-CI), "circle" (uses Circle-CI), "appveyor" (uses AppVeyor), or "gh-actions" (uses GitHub Actions).

    makefile

    Logical. If TRUE, adds a template makefile.R file to the project.

    pipe

    Logical. Use magrittr's pipe in your package?

    testthat

    Logical. Add testthat infrastructure?

    verbose

    Print verbose output in the console while creating the new project? Default is FALSE.

    open.project

    Logical. If TRUE (the default) will open the newly created Rstudio project in a new session.

    182 | 183 |

    Value

    184 | 185 |

    A new directory with R package structure, slightly modified.

    186 |

    Details

    187 | 188 |

    If using github = TRUE, you will be asked if you want to commit some files. Reply positively to continue.

    189 | 190 |

    Examples

    191 |
    if (FALSE) { 192 | library("template") 193 | new_project("myproject") 194 | new_project("myproject", github = TRUE, private.repo = TRUE) 195 | } 196 |
    197 |
    198 | 203 |
    204 | 205 | 206 |
    207 | 210 | 211 |
    212 |

    Site built with pkgdown 1.6.1.

    213 |
    214 | 215 |
    216 |
    217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | -------------------------------------------------------------------------------- /docs/reference/template-package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | template package — template-package • template 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
    66 |
    67 | 106 | 107 | 108 | 109 |
    110 | 111 |
    112 |
    113 | 118 | 119 |
    120 |

    Generic template for research projects structured as R packages. 121 | This package works as a template for new research projects, 122 | under the idea of having everything (data, R scripts, functions and manuscripts) 123 | contained in the same package to promote reproducibility.

    124 |
    125 | 126 | 127 | 128 |

    Details

    129 | 130 |

    For detailed steps on how to use the package see https://github.com/Pakillo/template/blob/master/README.md.

    131 |

    Author

    132 | 133 |

    Francisco Rodriguez-Sanchez

    134 | 135 |
    136 | 141 |
    142 | 143 | 144 | 154 |
    155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/template/349e5201c6952831e22fc346503d3ac4bb15ae40/files.png -------------------------------------------------------------------------------- /inst/makefile/makefile.R: -------------------------------------------------------------------------------- 1 | 2 | #### Template of a master script for the project #### 3 | 4 | ## Using an advanced tool like {drake} or {targets} is recommended, 5 | ## but this can work as a simple alternative. 6 | 7 | 8 | ### if you have written specific functions in R/, load the package: 9 | # library("myproject") 10 | 11 | 12 | ### Source data cleaning scripts 13 | # source("data-raw/datacleaning.R") 14 | ### Could also be Rmarkdown: 15 | # rmarkdown::render("data-raw/datacleaning.Rmd") 16 | 17 | 18 | ### Render manuscript 19 | # rmarkdown::render("manuscript/ms_project.Rmd") 20 | 21 | 22 | ## Check your code ## 23 | # goodpractice::gp() 24 | 25 | 26 | 27 | #### Control package dependencies #### 28 | 29 | # Many alternatives available, for example: 30 | 31 | # sessionInfo() 32 | 33 | # automagic::make_deps_file() 34 | 35 | # Or using renv: 36 | # renv::init() 37 | # renv::snapshot() 38 | 39 | # Or use Docker, see e.g. {containerit} or {liftr} 40 | 41 | 42 | ## Make a website for your project? 43 | ## see https://pkgdown.r-lib.org/ 44 | # usethis::use_pkgdown() 45 | # pkgdown::build_site() 46 | 47 | -------------------------------------------------------------------------------- /man/exampledataset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dataset.R 3 | \docType{data} 4 | \name{exampledataset} 5 | \alias{exampledataset} 6 | \title{How to document datasets.} 7 | \format{ 8 | A numeric vector. 9 | } 10 | \source{ 11 | This example modified from C. Boettiger's template package \url{https://github.com/cboettig/template}. 12 | } 13 | \description{ 14 | This is an example showing how to document datasets included in the package (in \code{data} folder): 15 | you must specify docType and name; do not forget NULL in the end. 16 | Can include other fields, like citation. 17 | See \url{http://r-pkgs.had.co.nz/data.html} for further explanations. 18 | } 19 | \examples{ 20 | \dontrun{ 21 | data(exampledataset) 22 | str(exampledataset) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /man/examplefunction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/function.R 3 | \name{examplefunction} 4 | \alias{examplefunction} 5 | \title{How to document functions.} 6 | \usage{ 7 | examplefunction(text) 8 | } 9 | \arguments{ 10 | \item{text}{Message to print.} 11 | } 12 | \description{ 13 | This is an example showing how to document functions to be included in the package. 14 | } 15 | \examples{ 16 | examplefunction('Hello world!') 17 | } 18 | \seealso{ 19 | \url{http://r-pkgs.had.co.nz/man.html} 20 | } 21 | \author{ 22 | Francisco Rodriguez-Sanchez 23 | } 24 | -------------------------------------------------------------------------------- /man/new_project.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/new_project.R 3 | \name{new_project} 4 | \alias{new_project} 5 | \title{Create new project scaffolding} 6 | \usage{ 7 | new_project( 8 | name, 9 | path = ".", 10 | package = TRUE, 11 | github = FALSE, 12 | private.repo = TRUE, 13 | ci = "none", 14 | makefile = TRUE, 15 | pipe = TRUE, 16 | testthat = FALSE, 17 | verbose = FALSE, 18 | open.project = TRUE 19 | ) 20 | } 21 | \arguments{ 22 | \item{name}{Character. Name of the new project. A new folder will be created with that name.} 23 | 24 | \item{path}{Character. Path where the new project should be created (default is the current working directory).} 25 | 26 | \item{package}{Logical. Create package structure or a simple project?} 27 | 28 | \item{github}{Logical. Create GitHub repository? Note this requires some working infrastructure like \code{git} and a \code{GITHUB_PAT}. See instructions here \url{https://usethis.r-lib.org/articles/articles/usethis-setup.html}.} 29 | 30 | \item{private.repo}{Logical. Default is TRUE.} 31 | 32 | \item{ci}{Logical. Use continuous integration in your GitHub repository? Current options are "none" (default), "travis" (uses Travis-CI), "circle" (uses Circle-CI), "appveyor" (uses AppVeyor), or "gh-actions" (uses GitHub Actions).} 33 | 34 | \item{makefile}{Logical. If TRUE, adds a template \code{makefile.R} file to the project.} 35 | 36 | \item{pipe}{Logical. Use magrittr's pipe in your package?} 37 | 38 | \item{testthat}{Logical. Add testthat infrastructure?} 39 | 40 | \item{verbose}{Print verbose output in the console while creating the new project? Default is FALSE.} 41 | 42 | \item{open.project}{Logical. If TRUE (the default) will open the newly created Rstudio project in a new session.} 43 | } 44 | \value{ 45 | A new directory with R package structure, slightly modified. 46 | } 47 | \description{ 48 | Create all the scaffolding for a new project in a new directory. The scaffolding includes a README file, different folders to hold raw data, analyses, etc, and optionally also \code{testthat} infrastructure. Also, optionally, set a private or public GitHub repo with continuous integration (Travis-CI, GitHub Actions...). 49 | } 50 | \details{ 51 | If using github = TRUE, you will be asked if you want to commit some files. Reply positively to continue. 52 | } 53 | \examples{ 54 | \dontrun{ 55 | library("template") 56 | new_project("myproject") 57 | new_project("myproject", github = TRUE, private.repo = TRUE) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /man/template-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/template-package.R 3 | \docType{package} 4 | \name{template-package} 5 | \alias{template-package} 6 | \title{template package} 7 | \description{ 8 | Generic template for research projects structured as R packages. 9 | This package works as a template for new research projects, 10 | under the idea of having everything (data, R scripts, functions and manuscripts) 11 | contained in the same package to promote reproducibility. 12 | } 13 | \details{ 14 | For detailed steps on how to use the package see \url{https://github.com/Pakillo/template/blob/master/README.md}. 15 | } 16 | \author{ 17 | Francisco Rodriguez-Sanchez 18 | } 19 | \keyword{package} 20 | -------------------------------------------------------------------------------- /manuscript/README.md: -------------------------------------------------------------------------------- 1 | Put here the master Rmarkdown document with the final analyses and figures. 2 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(template) 3 | 4 | test_check("template") 5 | -------------------------------------------------------------------------------- /tests/testthat/test_fake.R: -------------------------------------------------------------------------------- 1 | library(template) 2 | 3 | context("Fake test") 4 | 5 | test_that("examplefunction can be run", { 6 | output <- examplefunction("testing") 7 | expect_match(output, "testing") 8 | }) 9 | --------------------------------------------------------------------------------