├── .Rbuildignore ├── .Rprofile ├── .github ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ └── issue_template.md ├── SUPPORT.md └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ ├── pr-commands.yaml │ └── test-coverage.yaml ├── .gitignore ├── DESCRIPTION ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── create_project.R ├── create_symlink.R ├── data.R ├── starter-package.R ├── sysdata.rda ├── use_project_file.R ├── utils-keepers.R ├── utils-mappers.R ├── utils-project_root.R ├── utils-safely.R └── utils-walkers.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── codecov.yml ├── cran-comments.md ├── data-raw ├── analysis_project_templates.R ├── hex │ └── starter-hex.png └── project_templates.R ├── data └── project_templates.rda ├── inst ├── WORDLIST └── project_templates │ ├── analysis_template │ ├── analysis.Rmd │ ├── derived_variables.xlsx │ ├── doc_template.docx │ ├── references.bib │ ├── report.Rmd │ ├── sap.docx │ └── setup.Rmd │ ├── default_gitignore.txt │ ├── default_readme.md │ ├── default_rprofile.R │ └── default_rproj.Rproj ├── man ├── create_project.Rd ├── create_symlink.Rd ├── figures │ ├── README-pressure-1.png │ └── logo.png ├── project_templates.Rd ├── starter-package.Rd └── use_project_file.Rd ├── starter.Rproj ├── tests ├── spelling.R ├── testthat.R └── testthat │ ├── test-create_project.R │ └── test-create_symlink.R └── vignettes ├── .gitignore └── create_project.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^renv$ 2 | ^renv\.lock$ 3 | ^LICENSE\.md$ 4 | ^starter\.Rproj$ 5 | ^\.Rproj\.user$ 6 | ^README\.Rmd$ 7 | ^cran-comments\.md$ 8 | ^\.github$ 9 | ^data-raw$ 10 | ^codecov\.yml$ 11 | ^_pkgdown\.yml$ 12 | ^docs$ 13 | ^pkgdown$ 14 | ^CRAN-RELEASE$ 15 | ^revdep 16 | ^CRAN-SUBMISSION$ 17 | -------------------------------------------------------------------------------- /.Rprofile: -------------------------------------------------------------------------------- 1 | # this sets the dev folder in the libPath 2 | tryCatch( 3 | devtools::dev_mode(on = TRUE), 4 | error = function(e) invisible() 5 | ) 6 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards 42 | of acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies 54 | when an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail 56 | address, posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at [INSERT CONTACT 63 | METHOD]. All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series of 85 | actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or permanent 92 | ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within the 112 | community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.0, 118 | available at https://www.contributor-covenant.org/version/2/0/ 119 | code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at https:// 128 | www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to starter 2 | 3 | This outlines how to propose a change to starter. 4 | For more detailed info about contributing to this, and other tidyverse packages, please see the 5 | [**development contributing guide**](https://rstd.io/tidy-contrib). 6 | 7 | ## Fixing typos 8 | 9 | You can fix typos, spelling mistakes, or grammatical errors in the documentation directly using the GitHub web interface, as long as the changes are made in the _source_ file. 10 | This generally means you'll need to edit [roxygen2 comments](https://roxygen2.r-lib.org/articles/roxygen2.html) in an `.R`, not a `.Rd` file. 11 | You can find the `.R` file that generates the `.Rd` by reading the comment in the first line. 12 | 13 | ## Bigger changes 14 | 15 | If you want to make a bigger change, it's a good idea to first file an issue and make sure someone from the team agrees that it’s needed. 16 | If you’ve found a bug, please file an issue that illustrates the bug with a minimal 17 | [reprex](https://www.tidyverse.org/help/#reprex) (this will also help you write a unit test, if needed). 18 | 19 | ### Pull request process 20 | 21 | * Fork the package and clone onto your computer. If you haven't done this before, we recommend using `usethis::create_from_github("ddsjoberg/starter", fork = TRUE)`. 22 | 23 | * Install all development dependences with `devtools::install_dev_deps()`, and then make sure the package passes R CMD check by running `devtools::check()`. 24 | If R CMD check doesn't pass cleanly, it's a good idea to ask for help before continuing. 25 | * Create a Git branch for your pull request (PR). We recommend using `usethis::pr_init("brief-description-of-change")`. 26 | 27 | * Make your changes, commit to git, and then create a PR by running `usethis::pr_push()`, and following the prompts in your browser. 28 | The title of your PR should briefly describe the change. 29 | The body of your PR should contain `Fixes #issue-number`. 30 | 31 | * For user-facing changes, add a bullet to the top of `NEWS.md` (i.e. just below the first header). Follow the style described in . 32 | 33 | ### Code style 34 | 35 | * New code should follow the tidyverse [style guide](https://style.tidyverse.org). 36 | You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR. 37 | 38 | * We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation. 39 | 40 | * We use [testthat](https://cran.r-project.org/package=testthat) for unit tests. 41 | Contributions with test cases included are easier to accept. 42 | 43 | ## Code of Conduct 44 | 45 | Please note that the starter project is released with a 46 | [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this 47 | project you agree to abide by its terms. 48 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report or feature request 3 | about: Describe a bug you've seen or make a case for a new feature 4 | --- 5 | 6 | Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on or . 7 | 8 | Please include a minimal reproducible example (AKA a reprex). If you've never heard of a [reprex](http://reprex.tidyverse.org/) before, start by reading . 9 | 10 | Brief description of the problem 11 | 12 | ```r 13 | # insert reprex here 14 | ``` 15 | -------------------------------------------------------------------------------- /.github/SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Getting help with starter 2 | 3 | Thanks for using starter! 4 | Before filing an issue, there are a few places to explore and pieces to put together to make the process as smooth as possible. 5 | 6 | ## Make a reprex 7 | 8 | Start by making a minimal **repr**oducible **ex**ample using the [reprex](https://reprex.tidyverse.org/) package. 9 | If you haven't heard of or used reprex before, you're in for a treat! 10 | Seriously, reprex will make all of your R-question-asking endeavors easier (which is a pretty insane ROI for the five to ten minutes it'll take you to learn what it's all about). 11 | For additional reprex pointers, check out the [Get help!](https://www.tidyverse.org/help/) section of the tidyverse site. 12 | 13 | ## Where to ask? 14 | 15 | Armed with your reprex, the next step is to figure out [where to ask](https://www.tidyverse.org/help/#where-to-ask). 16 | 17 | * If it's a question: start with [community.rstudio.com](https://community.rstudio.com/), and/or StackOverflow. There are more people there to answer questions. 18 | 19 | * If it's a bug: you're in the right place, [file an issue](https://github.com/ddsjoberg/starter/issues/new). 20 | 21 | * If you're not sure: let the community help you figure it out! 22 | If your problem _is_ a bug or a feature request, you can easily return here and report it. 23 | 24 | Before opening a new issue, be sure to [search issues and pull requests](https://github.com/ddsjoberg/starter/issues) to make sure the bug hasn't been reported and/or already fixed in the development version. 25 | By default, the search will be pre-populated with `is:issue is:open`. 26 | You can [edit the qualifiers](https://help.github.com/articles/searching-issues-and-pull-requests/) (e.g. `is:pr`, `is:closed`) as needed. 27 | For example, you'd simply remove `is:open` to search _all_ issues in the repo, open or closed. 28 | 29 | ## What happens next? 30 | 31 | To be as efficient as possible, development of tidyverse packages tends to be very bursty, so you shouldn't worry if you don't get an immediate response. 32 | Typically we don't look at a repo until a sufficient quantity of issues accumulates, then there’s a burst of intense activity as we focus our efforts. 33 | That makes development more efficient because it avoids expensive context switching between problems, at the cost of taking longer to get back to you. 34 | This process makes a good reprex particularly important because it might be multiple months between your initial report and when we start working on it. 35 | If we can’t reproduce the bug, we can’t fix it! 36 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | # 4 | # NOTE: This workflow is overkill for most R packages and 5 | # check-standard.yaml is likely a better choice. 6 | # usethis::use_github_action("check-standard") will install it. 7 | on: 8 | push: 9 | branches: [main, master] 10 | pull_request: 11 | branches: [main, master] 12 | 13 | name: R-CMD-check 14 | 15 | jobs: 16 | R-CMD-check: 17 | runs-on: ${{ matrix.config.os }} 18 | 19 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | config: 25 | - {os: macOS-latest, r: 'release'} 26 | 27 | - {os: windows-latest, r: 'release'} 28 | 29 | # Use older ubuntu to maximise backward compatibility 30 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 31 | - {os: ubuntu-latest, r: 'release'} 32 | - {os: ubuntu-latest, r: 'oldrel-1'} 33 | - {os: ubuntu-latest, r: 'oldrel-2'} 34 | - {os: ubuntu-latest, r: 'oldrel-3'} 35 | - {os: ubuntu-latest, r: 'oldrel-4'} 36 | 37 | env: 38 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 39 | R_KEEP_PKG_SOURCE: yes 40 | 41 | steps: 42 | - uses: actions/checkout@v2 43 | 44 | - uses: r-lib/actions/setup-pandoc@v2 45 | 46 | - uses: r-lib/actions/setup-r@v2 47 | with: 48 | r-version: ${{ matrix.config.r }} 49 | http-user-agent: ${{ matrix.config.http-user-agent }} 50 | use-public-rspm: true 51 | 52 | - uses: r-lib/actions/setup-r-dependencies@v2 53 | with: 54 | extra-packages: any::rcmdcheck 55 | needs: check 56 | 57 | - uses: r-lib/actions/check-r-package@v2 58 | with: 59 | upload-snapshots: true 60 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | jobs: 15 | pkgdown: 16 | runs-on: ubuntu-latest 17 | # Only restrict concurrency for non-PR jobs 18 | concurrency: 19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - uses: r-lib/actions/setup-pandoc@v2 26 | 27 | - uses: r-lib/actions/setup-r@v2 28 | with: 29 | use-public-rspm: true 30 | 31 | - uses: r-lib/actions/setup-r-dependencies@v2 32 | with: 33 | extra-packages: any::pkgdown, local::. 34 | needs: website 35 | 36 | - name: Build site 37 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 38 | shell: Rscript {0} 39 | 40 | - name: Deploy to GitHub pages 🚀 41 | if: github.event_name != 'pull_request' 42 | uses: JamesIves/github-pages-deploy-action@4.1.4 43 | with: 44 | clean: false 45 | branch: gh-pages 46 | folder: docs 47 | -------------------------------------------------------------------------------- /.github/workflows/pr-commands.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | issue_comment: 5 | types: [created] 6 | 7 | name: Commands 8 | 9 | jobs: 10 | document: 11 | if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }} 12 | name: document 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | steps: 17 | - uses: actions/checkout@v2 18 | 19 | - uses: r-lib/actions/pr-fetch@v2 20 | with: 21 | repo-token: ${{ secrets.GITHUB_TOKEN }} 22 | 23 | - uses: r-lib/actions/setup-r@v2 24 | with: 25 | use-public-rspm: true 26 | 27 | - uses: r-lib/actions/setup-r-dependencies@v2 28 | with: 29 | extra-packages: any::roxygen2 30 | needs: pr-document 31 | 32 | - name: Document 33 | run: roxygen2::roxygenise() 34 | shell: Rscript {0} 35 | 36 | - name: commit 37 | run: | 38 | git config --local user.name "$GITHUB_ACTOR" 39 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 40 | git add man/\* NAMESPACE 41 | git commit -m 'Document' 42 | 43 | - uses: r-lib/actions/pr-push@v2 44 | with: 45 | repo-token: ${{ secrets.GITHUB_TOKEN }} 46 | 47 | style: 48 | if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} 49 | name: style 50 | runs-on: ubuntu-latest 51 | env: 52 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 53 | steps: 54 | - uses: actions/checkout@v2 55 | 56 | - uses: r-lib/actions/pr-fetch@v2 57 | with: 58 | repo-token: ${{ secrets.GITHUB_TOKEN }} 59 | 60 | - uses: r-lib/actions/setup-r@v2 61 | 62 | - name: Install dependencies 63 | run: install.packages("styler") 64 | shell: Rscript {0} 65 | 66 | - name: Style 67 | run: styler::style_pkg() 68 | shell: Rscript {0} 69 | 70 | - name: commit 71 | run: | 72 | git config --local user.name "$GITHUB_ACTOR" 73 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 74 | git add \*.R 75 | git commit -m 'Style' 76 | 77 | - uses: r-lib/actions/pr-push@v2 78 | with: 79 | repo-token: ${{ secrets.GITHUB_TOKEN }} 80 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: windows-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::covr 27 | needs: coverage 28 | 29 | - name: Test coverage 30 | run: covr::codecov(quiet = FALSE) 31 | shell: Rscript {0} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | docs 6 | inst/doc 7 | revdep 8 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: starter 2 | Title: Starter Kit for New Projects 3 | Version: 0.1.16.9000 4 | Authors@R: c( 5 | person("Daniel D.", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre"), 6 | comment = c(ORCID = "0000-0003-0862-2018")), 7 | person("Emily", "Vertosick", role = "ctb") 8 | ) 9 | Description: Get started with new projects by dropping a skeleton of a new 10 | project into a new or existing directory, initialise git repositories, 11 | and create reproducible environments with the 'renv' package. The 12 | package allows for dynamically named files, folders, file content, as 13 | well as the functionality to drop individual template files into 14 | existing projects. 15 | License: AGPL (>= 3) 16 | URL: https://github.com/ddsjoberg/starter, 17 | https://www.danieldsjoberg.com/starter/index.html 18 | BugReports: https://github.com/ddsjoberg/starter/issues 19 | Depends: 20 | R (>= 3.6) 21 | Imports: 22 | dplyr (>= 1.1.0), 23 | cli (>= 3.6.0), 24 | gert (>= 1.9.2), 25 | glue (>= 1.6.2), 26 | R.utils (>= 2.11.0), 27 | renv (>= 0.17.2), 28 | rlang (>= 1.0.6), 29 | rprojroot, 30 | rstudioapi 31 | Suggests: 32 | covr (>= 3.5.1), 33 | fs (>= 1.5.0), 34 | knitr (>= 1.34), 35 | pkgdown (>= 1.6.1), 36 | readr (>= 2.0.1), 37 | rmarkdown (>= 2.11), 38 | stringr, 39 | spelling (>= 2.2), 40 | testthat (>= 3.0.4) 41 | VignetteBuilder: 42 | knitr 43 | Config/testthat/edition: 3 44 | Encoding: UTF-8 45 | Language: en-US 46 | LazyData: true 47 | Roxygen: list(markdown = TRUE) 48 | RoxygenNote: 7.3.2 49 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU Affero General Public License 2 | ================================= 3 | 4 | _Version 3, 19 November 2007_ 5 | _Copyright (C) 2007 Free Software Foundation, Inc. <>_ 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this 8 | license document, but changing it is not allowed. 9 | 10 | ## Preamble 11 | 12 | The GNU Affero General Public License is a free, copyleft license for 13 | software and other kinds of works, specifically designed to ensure 14 | cooperation with the community in the case of network server software. 15 | 16 | The licenses for most software and other practical works are designed 17 | to take away your freedom to share and change the works. By contrast, 18 | our General Public Licenses are intended to guarantee your freedom to 19 | share and change all versions of a program--to make sure it remains 20 | free software for all its users. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | Developers that use our General Public Licenses protect your rights 30 | with two steps: (1) assert copyright on the software, and (2) offer 31 | you this License which gives you legal permission to copy, distribute 32 | and/or modify the software. 33 | 34 | A secondary benefit of defending all users' freedom is that 35 | improvements made in alternate versions of the program, if they 36 | receive widespread use, become available for other developers to 37 | incorporate. Many developers of free software are heartened and 38 | encouraged by the resulting cooperation. However, in the case of 39 | software used on network servers, this result may fail to come about. 40 | The GNU General Public License permits making a modified version and 41 | letting the public access it on a server without ever releasing its 42 | source code to the public. 43 | 44 | The GNU Affero General Public License is designed specifically to 45 | ensure that, in such cases, the modified source code becomes available 46 | to the community. It requires the operator of a network server to 47 | provide the source code of the modified version running there to the 48 | users of that server. Therefore, public use of a modified version, on 49 | a publicly accessible server, gives the public access to the source 50 | code of the modified version. 51 | 52 | An older license, called the Affero General Public License and 53 | published by Affero, was designed to accomplish similar goals. This is 54 | a different license, not a version of the Affero GPL, but Affero has 55 | released a new version of the Affero GPL which permits relicensing 56 | under this license. 57 | 58 | The precise terms and conditions for copying, distribution and 59 | modification follow. 60 | 61 | ## TERMS AND CONDITIONS 62 | 63 | ### 0. Definitions. 64 | 65 | "This License" refers to version 3 of the GNU Affero General Public 66 | License. 67 | 68 | "Copyright" also means copyright-like laws that apply to other kinds 69 | of works, such as semiconductor masks. 70 | 71 | "The Program" refers to any copyrightable work licensed under this 72 | License. Each licensee is addressed as "you". "Licensees" and 73 | "recipients" may be individuals or organizations. 74 | 75 | To "modify" a work means to copy from or adapt all or part of the work 76 | in a fashion requiring copyright permission, other than the making of 77 | an exact copy. The resulting work is called a "modified version" of 78 | the earlier work or a work "based on" the earlier work. 79 | 80 | A "covered work" means either the unmodified Program or a work based 81 | on the Program. 82 | 83 | To "propagate" a work means to do anything with it that, without 84 | permission, would make you directly or secondarily liable for 85 | infringement under applicable copyright law, except executing it on a 86 | computer or modifying a private copy. Propagation includes copying, 87 | distribution (with or without modification), making available to the 88 | public, and in some countries other activities as well. 89 | 90 | To "convey" a work means any kind of propagation that enables other 91 | parties to make or receive copies. Mere interaction with a user 92 | through a computer network, with no transfer of a copy, is not 93 | conveying. 94 | 95 | An interactive user interface displays "Appropriate Legal Notices" to 96 | the extent that it includes a convenient and prominently visible 97 | feature that (1) displays an appropriate copyright notice, and (2) 98 | tells the user that there is no warranty for the work (except to the 99 | extent that warranties are provided), that licensees may convey the 100 | work under this License, and how to view a copy of this License. If 101 | the interface presents a list of user commands or options, such as a 102 | menu, a prominent item in the list meets this criterion. 103 | 104 | ### 1. Source Code. 105 | 106 | The "source code" for a work means the preferred form of the work for 107 | making modifications to it. "Object code" means any non-source form of 108 | a work. 109 | 110 | A "Standard Interface" means an interface that either is an official 111 | standard defined by a recognized standards body, or, in the case of 112 | interfaces specified for a particular programming language, one that 113 | is widely used among developers working in that language. 114 | 115 | The "System Libraries" of an executable work include anything, other 116 | than the work as a whole, that (a) is included in the normal form of 117 | packaging a Major Component, but which is not part of that Major 118 | Component, and (b) serves only to enable use of the work with that 119 | Major Component, or to implement a Standard Interface for which an 120 | implementation is available to the public in source code form. A 121 | "Major Component", in this context, means a major essential component 122 | (kernel, window system, and so on) of the specific operating system 123 | (if any) on which the executable work runs, or a compiler used to 124 | produce the work, or an object code interpreter used to run it. 125 | 126 | The "Corresponding Source" for a work in object code form means all 127 | the source code needed to generate, install, and (for an executable 128 | work) run the object code and to modify the work, including scripts to 129 | control those activities. However, it does not include the work's 130 | System Libraries, or general-purpose tools or generally available free 131 | programs which are used unmodified in performing those activities but 132 | which are not part of the work. For example, Corresponding Source 133 | includes interface definition files associated with source files for 134 | the work, and the source code for shared libraries and dynamically 135 | linked subprograms that the work is specifically designed to require, 136 | such as by intimate data communication or control flow between those 137 | subprograms and other parts of the work. 138 | 139 | The Corresponding Source need not include anything that users can 140 | regenerate automatically from other parts of the Corresponding Source. 141 | 142 | The Corresponding Source for a work in source code form is that same 143 | work. 144 | 145 | ### 2. Basic Permissions. 146 | 147 | All rights granted under this License are granted for the term of 148 | copyright on the Program, and are irrevocable provided the stated 149 | conditions are met. This License explicitly affirms your unlimited 150 | permission to run the unmodified Program. The output from running a 151 | covered work is covered by this License only if the output, given its 152 | content, constitutes a covered work. This License acknowledges your 153 | rights of fair use or other equivalent, as provided by copyright law. 154 | 155 | You may make, run and propagate covered works that you do not convey, 156 | without conditions so long as your license otherwise remains in force. 157 | You may convey covered works to others for the sole purpose of having 158 | them make modifications exclusively for you, or provide you with 159 | facilities for running those works, provided that you comply with the 160 | terms of this License in conveying all material for which you do not 161 | control copyright. Those thus making or running the covered works for 162 | you must do so exclusively on your behalf, under your direction and 163 | control, on terms that prohibit them from making any copies of your 164 | copyrighted material outside their relationship with you. 165 | 166 | Conveying under any other circumstances is permitted solely under the 167 | conditions stated below. Sublicensing is not allowed; section 10 makes 168 | it unnecessary. 169 | 170 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 171 | 172 | No covered work shall be deemed part of an effective technological 173 | measure under any applicable law fulfilling obligations under article 174 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 175 | similar laws prohibiting or restricting circumvention of such 176 | measures. 177 | 178 | When you convey a covered work, you waive any legal power to forbid 179 | circumvention of technological measures to the extent such 180 | circumvention is effected by exercising rights under this License with 181 | respect to the covered work, and you disclaim any intention to limit 182 | operation or modification of the work as a means of enforcing, against 183 | the work's users, your or third parties' legal rights to forbid 184 | circumvention of technological measures. 185 | 186 | ### 4. Conveying Verbatim Copies. 187 | 188 | You may convey verbatim copies of the Program's source code as you 189 | receive it, in any medium, provided that you conspicuously and 190 | appropriately publish on each copy an appropriate copyright notice; 191 | keep intact all notices stating that this License and any 192 | non-permissive terms added in accord with section 7 apply to the code; 193 | keep intact all notices of the absence of any warranty; and give all 194 | recipients a copy of this License along with the Program. 195 | 196 | You may charge any price or no price for each copy that you convey, 197 | and you may offer support or warranty protection for a fee. 198 | 199 | ### 5. Conveying Modified Source Versions. 200 | 201 | You may convey a work based on the Program, or the modifications to 202 | produce it from the Program, in the form of source code under the 203 | terms of section 4, provided that you also meet all of these 204 | conditions: 205 | 206 | - a) The work must carry prominent notices stating that you modified 207 | it, and giving a relevant date. 208 | - b) The work must carry prominent notices stating that it is 209 | released under this License and any conditions added under 210 | section 7. This requirement modifies the requirement in section 4 211 | to "keep intact all notices". 212 | - c) You must license the entire work, as a whole, under this 213 | License to anyone who comes into possession of a copy. This 214 | License will therefore apply, along with any applicable section 7 215 | additional terms, to the whole of the work, and all its parts, 216 | regardless of how they are packaged. This License gives no 217 | permission to license the work in any other way, but it does not 218 | invalidate such permission if you have separately received it. 219 | - d) If the work has interactive user interfaces, each must display 220 | Appropriate Legal Notices; however, if the Program has interactive 221 | interfaces that do not display Appropriate Legal Notices, your 222 | work need not make them do so. 223 | 224 | A compilation of a covered work with other separate and independent 225 | works, which are not by their nature extensions of the covered work, 226 | and which are not combined with it such as to form a larger program, 227 | in or on a volume of a storage or distribution medium, is called an 228 | "aggregate" if the compilation and its resulting copyright are not 229 | used to limit the access or legal rights of the compilation's users 230 | beyond what the individual works permit. Inclusion of a covered work 231 | in an aggregate does not cause this License to apply to the other 232 | parts of the aggregate. 233 | 234 | ### 6. Conveying Non-Source Forms. 235 | 236 | You may convey a covered work in object code form under the terms of 237 | sections 4 and 5, provided that you also convey the machine-readable 238 | Corresponding Source under the terms of this License, in one of these 239 | ways: 240 | 241 | - a) Convey the object code in, or embodied in, a physical product 242 | (including a physical distribution medium), accompanied by the 243 | Corresponding Source fixed on a durable physical medium 244 | customarily used for software interchange. 245 | - b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the Corresponding 255 | Source from a network server at no charge. 256 | - c) Convey individual copies of the object code with a copy of the 257 | written offer to provide the Corresponding Source. This 258 | alternative is allowed only occasionally and noncommercially, and 259 | only if you received the object code with such an offer, in accord 260 | with subsection 6b. 261 | - d) Convey the object code by offering access from a designated 262 | place (gratis or for a charge), and offer equivalent access to the 263 | Corresponding Source in the same way through the same place at no 264 | further charge. You need not require recipients to copy the 265 | Corresponding Source along with the object code. If the place to 266 | copy the object code is a network server, the Corresponding Source 267 | may be on a different server (operated by you or a third party) 268 | that supports equivalent copying facilities, provided you maintain 269 | clear directions next to the object code saying where to find the 270 | Corresponding Source. Regardless of what server hosts the 271 | Corresponding Source, you remain obligated to ensure that it is 272 | available for as long as needed to satisfy these requirements. 273 | - e) Convey the object code using peer-to-peer transmission, 274 | provided you inform other peers where the object code and 275 | Corresponding Source of the work are being offered to the general 276 | public at no charge under subsection 6d. 277 | 278 | A separable portion of the object code, whose source code is excluded 279 | from the Corresponding Source as a System Library, need not be 280 | included in conveying the object code work. 281 | 282 | A "User Product" is either (1) a "consumer product", which means any 283 | tangible personal property which is normally used for personal, 284 | family, or household purposes, or (2) anything designed or sold for 285 | incorporation into a dwelling. In determining whether a product is a 286 | consumer product, doubtful cases shall be resolved in favor of 287 | coverage. For a particular product received by a particular user, 288 | "normally used" refers to a typical or common use of that class of 289 | product, regardless of the status of the particular user or of the way 290 | in which the particular user actually uses, or expects or is expected 291 | to use, the product. A product is a consumer product regardless of 292 | whether the product has substantial commercial, industrial or 293 | non-consumer uses, unless such uses represent the only significant 294 | mode of use of the product. 295 | 296 | "Installation Information" for a User Product means any methods, 297 | procedures, authorization keys, or other information required to 298 | install and execute modified versions of a covered work in that User 299 | Product from a modified version of its Corresponding Source. The 300 | information must suffice to ensure that the continued functioning of 301 | the modified object code is in no case prevented or interfered with 302 | solely because modification has been made. 303 | 304 | If you convey an object code work under this section in, or with, or 305 | specifically for use in, a User Product, and the conveying occurs as 306 | part of a transaction in which the right of possession and use of the 307 | User Product is transferred to the recipient in perpetuity or for a 308 | fixed term (regardless of how the transaction is characterized), the 309 | Corresponding Source conveyed under this section must be accompanied 310 | by the Installation Information. But this requirement does not apply 311 | if neither you nor any third party retains the ability to install 312 | modified object code on the User Product (for example, the work has 313 | been installed in ROM). 314 | 315 | The requirement to provide Installation Information does not include a 316 | requirement to continue to provide support service, warranty, or 317 | updates for a work that has been modified or installed by the 318 | recipient, or for the User Product in which it has been modified or 319 | installed. Access to a network may be denied when the modification 320 | itself materially and adversely affects the operation of the network 321 | or violates the rules and protocols for communication across the 322 | network. 323 | 324 | Corresponding Source conveyed, and Installation Information provided, 325 | in accord with this section must be in a format that is publicly 326 | documented (and with an implementation available to the public in 327 | source code form), and must require no special password or key for 328 | unpacking, reading or copying. 329 | 330 | ### 7. Additional Terms. 331 | 332 | "Additional permissions" are terms that supplement the terms of this 333 | License by making exceptions from one or more of its conditions. 334 | Additional permissions that are applicable to the entire Program shall 335 | be treated as though they were included in this License, to the extent 336 | that they are valid under applicable law. If additional permissions 337 | apply only to part of the Program, that part may be used separately 338 | under those permissions, but the entire Program remains governed by 339 | this License without regard to the additional permissions. 340 | 341 | When you convey a copy of a covered work, you may at your option 342 | remove any additional permissions from that copy, or from any part of 343 | it. (Additional permissions may be written to require their own 344 | removal in certain cases when you modify the work.) You may place 345 | additional permissions on material, added by you to a covered work, 346 | for which you have or can give appropriate copyright permission. 347 | 348 | Notwithstanding any other provision of this License, for material you 349 | add to a covered work, you may (if authorized by the copyright holders 350 | of that material) supplement the terms of this License with terms: 351 | 352 | - a) Disclaiming warranty or limiting liability differently from the 353 | terms of sections 15 and 16 of this License; or 354 | - b) Requiring preservation of specified reasonable legal notices or 355 | author attributions in that material or in the Appropriate Legal 356 | Notices displayed by works containing it; or 357 | - c) Prohibiting misrepresentation of the origin of that material, 358 | or requiring that modified versions of such material be marked in 359 | reasonable ways as different from the original version; or 360 | - d) Limiting the use for publicity purposes of names of licensors 361 | or authors of the material; or 362 | - e) Declining to grant rights under trademark law for use of some 363 | trade names, trademarks, or service marks; or 364 | - f) Requiring indemnification of licensors and authors of that 365 | material by anyone who conveys the material (or modified versions 366 | of it) with contractual assumptions of liability to the recipient, 367 | for any liability that these contractual assumptions directly 368 | impose on those licensors and authors. 369 | 370 | All other non-permissive additional terms are considered "further 371 | restrictions" within the meaning of section 10. If the Program as you 372 | received it, or any part of it, contains a notice stating that it is 373 | governed by this License along with a term that is a further 374 | restriction, you may remove that term. If a license document contains 375 | a further restriction but permits relicensing or conveying under this 376 | License, you may add to a covered work material governed by the terms 377 | of that license document, provided that the further restriction does 378 | not survive such relicensing or conveying. 379 | 380 | If you add terms to a covered work in accord with this section, you 381 | must place, in the relevant source files, a statement of the 382 | additional terms that apply to those files, or a notice indicating 383 | where to find the applicable terms. 384 | 385 | Additional terms, permissive or non-permissive, may be stated in the 386 | form of a separately written license, or stated as exceptions; the 387 | above requirements apply either way. 388 | 389 | ### 8. Termination. 390 | 391 | You may not propagate or modify a covered work except as expressly 392 | provided under this License. Any attempt otherwise to propagate or 393 | modify it is void, and will automatically terminate your rights under 394 | this License (including any patent licenses granted under the third 395 | paragraph of section 11). 396 | 397 | However, if you cease all violation of this License, then your license 398 | from a particular copyright holder is reinstated (a) provisionally, 399 | unless and until the copyright holder explicitly and finally 400 | terminates your license, and (b) permanently, if the copyright holder 401 | fails to notify you of the violation by some reasonable means prior to 402 | 60 days after the cessation. 403 | 404 | Moreover, your license from a particular copyright holder is 405 | reinstated permanently if the copyright holder notifies you of the 406 | violation by some reasonable means, this is the first time you have 407 | received notice of violation of this License (for any work) from that 408 | copyright holder, and you cure the violation prior to 30 days after 409 | your receipt of the notice. 410 | 411 | Termination of your rights under this section does not terminate the 412 | licenses of parties who have received copies or rights from you under 413 | this License. If your rights have been terminated and not permanently 414 | reinstated, you do not qualify to receive new licenses for the same 415 | material under section 10. 416 | 417 | ### 9. Acceptance Not Required for Having Copies. 418 | 419 | You are not required to accept this License in order to receive or run 420 | a copy of the Program. Ancillary propagation of a covered work 421 | occurring solely as a consequence of using peer-to-peer transmission 422 | to receive a copy likewise does not require acceptance. However, 423 | nothing other than this License grants you permission to propagate or 424 | modify any covered work. These actions infringe copyright if you do 425 | not accept this License. Therefore, by modifying or propagating a 426 | covered work, you indicate your acceptance of this License to do so. 427 | 428 | ### 10. Automatic Licensing of Downstream Recipients. 429 | 430 | Each time you convey a covered work, the recipient automatically 431 | receives a license from the original licensors, to run, modify and 432 | propagate that work, subject to this License. You are not responsible 433 | for enforcing compliance by third parties with this License. 434 | 435 | An "entity transaction" is a transaction transferring control of an 436 | organization, or substantially all assets of one, or subdividing an 437 | organization, or merging organizations. If propagation of a covered 438 | work results from an entity transaction, each party to that 439 | transaction who receives a copy of the work also receives whatever 440 | licenses to the work the party's predecessor in interest had or could 441 | give under the previous paragraph, plus a right to possession of the 442 | Corresponding Source of the work from the predecessor in interest, if 443 | the predecessor has it or can get it with reasonable efforts. 444 | 445 | You may not impose any further restrictions on the exercise of the 446 | rights granted or affirmed under this License. For example, you may 447 | not impose a license fee, royalty, or other charge for exercise of 448 | rights granted under this License, and you may not initiate litigation 449 | (including a cross-claim or counterclaim in a lawsuit) alleging that 450 | any patent claim is infringed by making, using, selling, offering for 451 | sale, or importing the Program or any portion of it. 452 | 453 | ### 11. Patents. 454 | 455 | A "contributor" is a copyright holder who authorizes use under this 456 | License of the Program or a work on which the Program is based. The 457 | work thus licensed is called the contributor's "contributor version". 458 | 459 | A contributor's "essential patent claims" are all patent claims owned 460 | or controlled by the contributor, whether already acquired or 461 | hereafter acquired, that would be infringed by some manner, permitted 462 | by this License, of making, using, or selling its contributor version, 463 | but do not include claims that would be infringed only as a 464 | consequence of further modification of the contributor version. For 465 | purposes of this definition, "control" includes the right to grant 466 | patent sublicenses in a manner consistent with the requirements of 467 | this License. 468 | 469 | Each contributor grants you a non-exclusive, worldwide, royalty-free 470 | patent license under the contributor's essential patent claims, to 471 | make, use, sell, offer for sale, import and otherwise run, modify and 472 | propagate the contents of its contributor version. 473 | 474 | In the following three paragraphs, a "patent license" is any express 475 | agreement or commitment, however denominated, not to enforce a patent 476 | (such as an express permission to practice a patent or covenant not to 477 | sue for patent infringement). To "grant" such a patent license to a 478 | party means to make such an agreement or commitment not to enforce a 479 | patent against the party. 480 | 481 | If you convey a covered work, knowingly relying on a patent license, 482 | and the Corresponding Source of the work is not available for anyone 483 | to copy, free of charge and under the terms of this License, through a 484 | publicly available network server or other readily accessible means, 485 | then you must either (1) cause the Corresponding Source to be so 486 | available, or (2) arrange to deprive yourself of the benefit of the 487 | patent license for this particular work, or (3) arrange, in a manner 488 | consistent with the requirements of this License, to extend the patent 489 | license to downstream recipients. "Knowingly relying" means you have 490 | actual knowledge that, but for the patent license, your conveying the 491 | covered work in a country, or your recipient's use of the covered work 492 | in a country, would infringe one or more identifiable patents in that 493 | country that you have reason to believe are valid. 494 | 495 | If, pursuant to or in connection with a single transaction or 496 | arrangement, you convey, or propagate by procuring conveyance of, a 497 | covered work, and grant a patent license to some of the parties 498 | receiving the covered work authorizing them to use, propagate, modify 499 | or convey a specific copy of the covered work, then the patent license 500 | you grant is automatically extended to all recipients of the covered 501 | work and works based on it. 502 | 503 | A patent license is "discriminatory" if it does not include within the 504 | scope of its coverage, prohibits the exercise of, or is conditioned on 505 | the non-exercise of one or more of the rights that are specifically 506 | granted under this License. You may not convey a covered work if you 507 | are a party to an arrangement with a third party that is in the 508 | business of distributing software, under which you make payment to the 509 | third party based on the extent of your activity of conveying the 510 | work, and under which the third party grants, to any of the parties 511 | who would receive the covered work from you, a discriminatory patent 512 | license (a) in connection with copies of the covered work conveyed by 513 | you (or copies made from those copies), or (b) primarily for and in 514 | connection with specific products or compilations that contain the 515 | covered work, unless you entered into that arrangement, or that patent 516 | license was granted, prior to 28 March 2007. 517 | 518 | Nothing in this License shall be construed as excluding or limiting 519 | any implied license or other defenses to infringement that may 520 | otherwise be available to you under applicable patent law. 521 | 522 | ### 12. No Surrender of Others' Freedom. 523 | 524 | If conditions are imposed on you (whether by court order, agreement or 525 | otherwise) that contradict the conditions of this License, they do not 526 | excuse you from the conditions of this License. If you cannot convey a 527 | covered work so as to satisfy simultaneously your obligations under 528 | this License and any other pertinent obligations, then as a 529 | consequence you may not convey it at all. For example, if you agree to 530 | terms that obligate you to collect a royalty for further conveying 531 | from those to whom you convey the Program, the only way you could 532 | satisfy both those terms and this License would be to refrain entirely 533 | from conveying the Program. 534 | 535 | ### 13. Remote Network Interaction; Use with the GNU General Public License. 536 | 537 | Notwithstanding any other provision of this License, if you modify the 538 | Program, your modified version must prominently offer all users 539 | interacting with it remotely through a computer network (if your 540 | version supports such interaction) an opportunity to receive the 541 | Corresponding Source of your version by providing access to the 542 | Corresponding Source from a network server at no charge, through some 543 | standard or customary means of facilitating copying of software. This 544 | Corresponding Source shall include the Corresponding Source for any 545 | work covered by version 3 of the GNU General Public License that is 546 | incorporated pursuant to the following paragraph. 547 | 548 | Notwithstanding any other provision of this License, you have 549 | permission to link or combine any covered work with a work licensed 550 | under version 3 of the GNU General Public License into a single 551 | combined work, and to convey the resulting work. The terms of this 552 | License will continue to apply to the part which is the covered work, 553 | but the work with which it is combined will remain governed by version 554 | 3 of the GNU General Public License. 555 | 556 | ### 14. Revised Versions of this License. 557 | 558 | The Free Software Foundation may publish revised and/or new versions 559 | of the GNU Affero General Public License from time to time. Such new 560 | versions will be similar in spirit to the present version, but may 561 | differ in detail to address new problems or concerns. 562 | 563 | Each version is given a distinguishing version number. If the Program 564 | specifies that a certain numbered version of the GNU Affero General 565 | Public License "or any later version" applies to it, you have the 566 | option of following the terms and conditions either of that numbered 567 | version or of any later version published by the Free Software 568 | Foundation. If the Program does not specify a version number of the 569 | GNU Affero General Public License, you may choose any version ever 570 | published by the Free Software Foundation. 571 | 572 | If the Program specifies that a proxy can decide which future versions 573 | of the GNU Affero General Public License can be used, that proxy's 574 | public statement of acceptance of a version permanently authorizes you 575 | to choose that version for the Program. 576 | 577 | Later license versions may give you additional or different 578 | permissions. However, no additional obligations are imposed on any 579 | author or copyright holder as a result of your choosing to follow a 580 | later version. 581 | 582 | ### 15. Disclaimer of Warranty. 583 | 584 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 585 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 586 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT 587 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT 588 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 589 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 590 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 591 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 592 | CORRECTION. 593 | 594 | ### 16. Limitation of Liability. 595 | 596 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 597 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR 598 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 599 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES 600 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT 601 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR 602 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM 603 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 604 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 605 | 606 | ### 17. Interpretation of Sections 15 and 16. 607 | 608 | If the disclaimer of warranty and limitation of liability provided 609 | above cannot be given local legal effect according to their terms, 610 | reviewing courts shall apply local law that most closely approximates 611 | an absolute waiver of all civil liability in connection with the 612 | Program, unless a warranty or assumption of liability accompanies a 613 | copy of the Program in return for a fee. 614 | 615 | END OF TERMS AND CONDITIONS 616 | 617 | ## How to Apply These Terms to Your New Programs 618 | 619 | If you develop a new program, and you want it to be of the greatest 620 | possible use to the public, the best way to achieve this is to make it 621 | free software which everyone can redistribute and change under these 622 | terms. 623 | 624 | To do so, attach the following notices to the program. It is safest to 625 | attach them to the start of each source file to most effectively state 626 | the exclusion of warranty; and each file should have at least the 627 | "copyright" line and a pointer to where the full notice is found. 628 | 629 | 630 | Copyright (C) 631 | 632 | This program is free software: you can redistribute it and/or modify 633 | it under the terms of the GNU Affero General Public License as 634 | published by the Free Software Foundation, either version 3 of the 635 | License, or (at your option) any later version. 636 | 637 | This program is distributed in the hope that it will be useful, 638 | but WITHOUT ANY WARRANTY; without even the implied warranty of 639 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 640 | GNU Affero General Public License for more details. 641 | 642 | You should have received a copy of the GNU Affero General Public License 643 | along with this program. If not, see . 644 | 645 | Also add information on how to contact you by electronic and paper 646 | mail. 647 | 648 | If your software can interact with users remotely through a computer 649 | network, you should also make sure that it provides a way for users to 650 | get its source. For example, if your program is a web application, its 651 | interface could display a "Source" link that leads users to an archive 652 | of the code. There are many ways you could offer source, and different 653 | solutions will be better for different programs; see section 13 for 654 | the specific requirements. 655 | 656 | You should also get your employer (if you work as a programmer) or 657 | school, if any, to sign a "copyright disclaimer" for the program, if 658 | necessary. For more information on this, and how to apply and follow 659 | the GNU AGPL, see . 660 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(create_project) 4 | export(create_symlink) 5 | export(use_project_file) 6 | export(use_project_gitignore) 7 | export(use_project_readme) 8 | importFrom(dplyr,"%>%") 9 | importFrom(rlang,"%||%") 10 | importFrom(rlang,.data) 11 | importFrom(rlang,.env) 12 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # starter (development version) 2 | 3 | # starter 0.1.16 4 | 5 | * Resubmitting to CRAN to address a NOTE about HTML manual builds. 6 | 7 | # starter 0.1.15 8 | 9 | * The {stringr} package was added to Suggests due to upcoming changes in the {rmarkdown} package. (#47, @yihui) 10 | 11 | # starter 0.1.14 12 | 13 | * Removed dependency on the {here} package and replaced with {rprojroot}. 14 | 15 | # starter 0.1.13 16 | 17 | * Added `mustWork = FALSE` argument to a `normalizePath()` call to avoid warning when `path_data=` is not a local folder (e.g. no warnings when a SharePoint location is passed for the data location). 18 | 19 | # starter 0.1.12 20 | 21 | * Removed `browser()` that was left in the package from a previous debugging session. 22 | 23 | # starter 0.1.11 24 | 25 | * Removed {usethis} dependency. Moved {fs} and {readr} from 'Imports' to 'Suggests'. 26 | 27 | * Environment update to ensure function runs without error when `create_project()` asks about over-writing an existing file. 28 | 29 | * Updated messaging symbols when symbolic link is placed (#37) 30 | 31 | # starter 0.1.10 32 | 33 | * Updated the sample `.Rprofile` template file with improved checking of the renv project status before messaging users. Previously, we checked the installed packages for the project; if no packages (except renv) were installed, the user saw a message about hydrating the package. But this message would appear each time an existing project was cloned to a new machine where `renv::restore()` had yet to be run. We now check the `renv.lock` file for the recorded packages instead of installed packages. (#27) 34 | 35 | * Removed {tibble}, {stringr}, and {purrr} dependencies. 36 | 37 | * Better messaging when placing a project skeleton into a folder that is already a git repo: users won't be asked if they want to create a git repo when it already exists. (#26) 38 | 39 | * Exporting the project templates in `project_templates`. `project_templates[["default"]]` is a simple example of template usage, and `project_templates[["analysis"]]` is a template including scripts to prepare an analysis project. (#28) 40 | 41 | # starter 0.1.9 42 | 43 | * Added `{{folder_first_word}}` to objects available to use in the project templates. Evaluates to the first "word" in the folder name, where the word separator is either a space or hyphen. 44 | 45 | * Added `create_project(renv.settings=)` argument. 46 | 47 | * No longer using `renv::scaffold(settings = list(snapshot.type = 'all'))` as the default. 48 | 49 | * Improved messaging in the default `.Rprofile` template file to finish setting up the renv project. 50 | 51 | # starter 0.1.8 52 | 53 | * Fix for the `use_project_file()` function when the template has an element that evaluates to `NULL` (which resulted in an indexing error). (#19) 54 | 55 | # starter 0.1.7 56 | 57 | * Allowing users to use their template to override function arguments in `create_project()`. This way, if the user never uses git, for example, this can be communicated in the template, rather than needing to change the function argument every time. 58 | 59 | * Added `create_project(symlink=)` argument indicating whether or not to place a symbolic link to the folder indicated in `create_project(path_data=).` 60 | 61 | * Updated `.Rprofile` start-up message for new repositories to include the `renv::snapshot()` step. 62 | 63 | # starter 0.1.6 64 | 65 | * Updated `create_symlink()` to pass the full path to `R.utils::createLink(link=)` instead of just the folder name. This solves an issue when creating symbolic links without full admin rights. 66 | 67 | # starter 0.1.5 68 | 69 | * Default snapshot type is now 'all'. 70 | 71 | * Removed 'rstudioapi' package dependency. 72 | 73 | * Bug fix in `create_project(overwrite=)` where existing files were not being prompted with inquiry whether to overwrite. 74 | 75 | * Documentation updates. 76 | 77 | # starter 0.1.4 78 | 79 | * Documentation updates and tidying up for CRAN submission. 80 | 81 | * Removed path normalization RStudio add-in. 82 | 83 | # starter 0.1.3 84 | 85 | * No longer tracking the latest release of the rstudio.prefs package on GitHub, because it causes an issue with renv. 86 | 87 | # starter 0.1.2 88 | 89 | * Now evaluating the template attribute `"script_path"` to allow users to quote the file location. 90 | 91 | # starter 0.1.1 92 | 93 | * When `create_project(renv = TRUE)`, `renv::init()` has been switched to `renv::scaffold()`. This stops renv from initializing the project. The user must call `renv::hydrate()` in order to discover the packages used in the project's `*.R` and `*.Rmd` files and have them added to the `renv.lock` file. 94 | 95 | * When a user specifies an attribute to the template list called `"script_path"`, the path is sourced. 96 | 97 | # starter 0.1.0 98 | 99 | * First release 100 | -------------------------------------------------------------------------------- /R/create_project.R: -------------------------------------------------------------------------------- 1 | #' Start a new project 2 | #' 3 | #' Creates a directory with the essential files for 4 | #' a new project. The function can be used on existing project directories as well. 5 | #' Existing files will *not* be overwritten; rather, the user will be prompted 6 | #' whether to replace the existing file with the template file. 7 | #' 8 | #' @section Personalized Template: 9 | #' Users can create a 10 | #' personalized project template. Check out the 11 | #' \href{https://www.danieldsjoberg.com/starter/articles/create_project.html}{vignette} 12 | #' for step by step instructions. 13 | #' 14 | #' @param path A path. If it exists, it is used. If it does not exist, it is 15 | #' created. 16 | #' @param path_data A path. The directory where the secure data exist. Default is 17 | #' `NULL`. When supplied, a symbolic link to data folder will be created. 18 | #' @param template A project template. See 19 | #' \href{https://www.danieldsjoberg.com/starter/articles/create_project.html}{vignette} 20 | #' for details. 21 | #' @param git Logical indicating whether to create Git repository. Default is `TRUE` 22 | #' When `NA`, user will be prompted whether to initialise Git repo. 23 | #' @param renv Logical indicating whether to add renv to a project. 24 | #' Default is `TRUE`. When `NA` user is asked interactively for preference. 25 | #' @param overwrite Logical indicating whether to overwrite existing files 26 | #' if they exist. Options are 27 | #' `TRUE`, `FALSE`, and `NA` (aka ask interactively). Default is `NA` 28 | #' @param open Logical indicating whether to open new project in fresh RStudio 29 | #' session 30 | #' @param symlink Logical indicating whether to place a symbolic link 31 | #' to the location in `path_data=`. Default is to place the symbolic link 32 | #' if the project is a git repository. 33 | #' @param renv.settings A list of renv settings passed to `renv::scaffold(settings=)` 34 | #' 35 | #' @author Daniel D. Sjoberg 36 | #' @export 37 | #' @returns NULL, places project template in new or existing directory 38 | #' @examplesIf pkgdown::in_pkgdown() 39 | #' # specifying project folder location (folder does not yet exist) 40 | #' project_path <- file.path(tempdir(), "My Project Folder") 41 | #' 42 | #' # creating folder where secure data would be stored (typically will be a network drive) 43 | #' secure_data_path <- file.path(tempdir(), "secure_data") 44 | #' dir.create(secure_data_path) 45 | #' 46 | #' # creating new project folder 47 | #' create_project(project_path, path_data = secure_data_path) 48 | #' @seealso [`use_project_file()`] 49 | #' @seealso [Vignette for `create_project()`](https://www.danieldsjoberg.com/starter/articles/create_project.html) 50 | 51 | create_project <- function(path, path_data = NULL, template = "default", 52 | git = TRUE, renv = TRUE, symlink = git, 53 | renv.settings = NULL, 54 | overwrite = NA, open = interactive()) { 55 | # check if template has function arg override -------------------------------- 56 | if (!is.null(template) && !is.null(attr(template, "arg_override"))) { 57 | override_arg_list <- attr(template, "arg_override") 58 | 59 | # print note about args being set 60 | 61 | walk2( 62 | override_arg_list, 63 | names(override_arg_list), 64 | function(arg, name) { 65 | if (!identical(arg, eval(parse(text = name)))) 66 | cli::cli_alert_success("Using template argument override {.code {paste(name, deparse(arg, width.cutoff = 200L), sep = ' = ')}}") 67 | } 68 | ) 69 | list2env(override_arg_list, envir = rlang::current_env()) 70 | } 71 | 72 | # ask user ------------------------------------------------------------------- 73 | if (!isTRUE(git) && is_git(path)) git <- TRUE # if folder is already git, don't ask about it. 74 | 75 | if (is.na(git)) 76 | git <- ifelse(!interactive(), TRUE, ui_yeah2("Initialise Git repo?")) 77 | if (is.na(renv)) 78 | renv <- ifelse(!interactive(), TRUE, ui_yeah2("Initialise renv project?")) 79 | if (is.na(symlink)) 80 | symlink <- ifelse(!interactive(), TRUE, ui_yeah2("Place symbolic link?")) 81 | 82 | # import template ------------------------------------------------------------ 83 | template <- evaluate_project_template(template, path, git, renv, symlink) 84 | 85 | # writing files and folders -------------------------------------------------- 86 | writing_files_folders( 87 | selected_template = template, 88 | path = path, 89 | overwrite = overwrite, 90 | path_data = path_data, 91 | git = git, renv = renv 92 | ) 93 | 94 | # setting symbolic link if provided ------------------------------------------ 95 | if (isTRUE(symlink) && !is.null(path_data)) { 96 | R.utils::createLink( 97 | target = glue::glue("{path_data}"), 98 | link = file.path(glue::glue("{path}"), "secure_data") 99 | ) 100 | cli::cli_alert_success("Creating symbolic link to data folder {.file {path_data}}") 101 | } 102 | 103 | # initializing git repo ------------------------------------------------------ 104 | initialise_git(git, path) 105 | 106 | # initializing renv project -------------------------------------------------- 107 | if (isTRUE(renv)) { 108 | cli::cli_alert_success("Initialising {.pkg renv} project") 109 | # set up structure of renv project 110 | renv::scaffold(project = path, settings = renv.settings) 111 | } 112 | 113 | # if user added a path to a script, run it ----------------------------------- 114 | if (!is.null(attr(template, "script_path"))) { 115 | cli::cli_alert_success("Sourcing template script") 116 | source(file = attr(template, "script_path"), local = rlang::current_env()) 117 | } 118 | 119 | # finishing up --------------------------------------------------------------- 120 | # opening new R project 121 | if (isTRUE(open) && rstudioapi::isAvailable() && has_rproj(path)) { 122 | rstudioapi::openProject(path, newSession = TRUE) 123 | } 124 | return(invisible()) 125 | } 126 | 127 | evaluate_project_template <- function(template, path, git, renv, symlink) { 128 | if (is.null(template)) template <- project_templates[["default"]] 129 | if (rlang::is_string(template)) { 130 | template <- 131 | switch( 132 | template, 133 | "default" = project_templates[["default"]] 134 | ) %||% 135 | project_templates[["default"]] 136 | } 137 | attr(template, "label") %||% 138 | "User-defined Template" %>% 139 | {cli::cli_alert_success("Using {.val {.}} template")} 140 | 141 | script_path <- attr(template, "script_path") %>% eval() 142 | 143 | # eval() quoted template list ------------------------------------------------ 144 | tryCatch({ 145 | selected_template <- eval_nested_lists(template, path, git, renv) 146 | }, 147 | warning = function(w) {warning(w)}, 148 | error = function(e) { 149 | cli::cli_alert_danger( 150 | paste( 151 | "There was as error evaluating the the list defining the project template.\n", 152 | "If this is a template stored in the package, please file\n", 153 | "a GitHub Issue illustrating the error. If this is a personal template,\n", 154 | "review the vignette on creating a personal project template." 155 | ) 156 | ) 157 | stop(e) 158 | }) 159 | 160 | # old name for glue was copy, update it -------------------------------------- 161 | selected_template <- copy_to_glue(selected_template) 162 | 163 | # adding script path attribute back ------------------------------------------ 164 | attr(selected_template, "script_path") <- script_path 165 | 166 | # checking imported template is named list ----------------------------------- 167 | check_template_structure(selected_template) 168 | 169 | # return evaluated template -------------------------------------------------- 170 | selected_template 171 | } 172 | 173 | # check the structure of the passed template object 174 | check_template_structure <- function(selected_template) { 175 | # check input is a named list 176 | if (!rlang::is_list(selected_template) || !rlang::is_named(selected_template)) { 177 | stop("Expecting a named list in `template=`", call. = FALSE) 178 | } 179 | 180 | if (!is.null(attr(selected_template, "script_path")) && 181 | !file.exists(attr(selected_template, "script_path"))) { 182 | paste("Template attribute 'script_path' must be a file location.") %>% 183 | stop(call. = FALSE) 184 | } 185 | 186 | for (i in names(selected_template)) { 187 | # check each files meta data is a named list 188 | if (!rlang::is_list(selected_template[[i]]) || 189 | !rlang::is_named(selected_template[[i]])) 190 | glue::glue("Template meta data for '{i}' must be a named list.") %>% 191 | stop(call. = FALSE) 192 | # check the named list has the correct names 193 | if (!setequal(names(selected_template[[i]]), c("template_filename", "filename", "glue")) && 194 | !setequal(names(selected_template[[i]]), c("template_filename", "filename", "copy"))) 195 | glue::glue("Expecting elements of template list '{i}' to have ", 196 | "names {paste(shQuote(c('template_filename', 'filename', 'glue'), type = 'csh'), collapse = ', ')}.") %>% 197 | stop(call. = FALSE) 198 | # check the types for each element are correct 199 | copy_or_glue <- names(selected_template[[i]]) %>% intersect(c("glue", "copy")) 200 | if (!rlang::is_string(selected_template[[i]][["template_filename"]]) || 201 | !rlang::is_string(selected_template[[i]][["filename"]]) || 202 | !rlang::is_logical(selected_template[[i]][[copy_or_glue]])) 203 | glue::glue("Expecting elements of template list '{i}' to have specific classes: ", 204 | "'template_filename') and 'filename' must be strings ", 205 | "and {copy_or_glue} logical.") %>% 206 | stop(call. = FALSE) 207 | # check the template file exists 208 | if (!file.exists(selected_template[[i]][["template_filename"]])) 209 | glue::glue("Template file '{selected_template[[i]][['template_filename']]}' ", 210 | "does not exist.") %>% 211 | stop(call. = FALSE) 212 | 213 | } 214 | } 215 | 216 | # this function iterates over each element of 217 | # nested lists, and evaluates the quote or expr 218 | eval_nested_lists <- function(template, path, git, renv) { 219 | template <- eval_if_call_or_expr(template, path, git, renv) 220 | if (!rlang::is_list(template)) return(template) 221 | 222 | template_evaluated <- 223 | vector(mode = "list", length = length(template)) %>% 224 | stats::setNames(names(template)) %>% 225 | map(~list()) 226 | # iterating over list to evaluate quoted/expr elements 227 | for (i in seq_len(length(template))) { 228 | if (rlang::is_list(template[[i]])) { 229 | for (j in seq_len(length(template[[i]]))) { 230 | template_evaluated[[i]][j] <- 231 | eval_if_call_or_expr(template[[i]][[j]], path, git, renv) %>% 232 | list() %>% 233 | stats::setNames(names(template[[i]][j])) 234 | } 235 | # remove empty elements after evaluating 236 | template_evaluated[i] <- 237 | compact(template[[i]]) %>% 238 | list() %>% 239 | stats::setNames(names(template[i])) 240 | } 241 | else template_evaluated[i] <- 242 | eval_if_call_or_expr(template[[i]], path, git, renv) %>% 243 | list() %>% 244 | stats::setNames(names(template[i])) 245 | } 246 | 247 | # remove empty elements after evaluating and return 248 | compact(template_evaluated) 249 | } 250 | 251 | eval_if_call_or_expr <- function(x, path, git, renv) { 252 | # strings that may be needed in the evaluation of some strings 253 | folder_name <- basename(path) 254 | folder_first_word <- 255 | strsplit(x = folder_name, split = ' |-')[[1]][1] %>% 256 | tolower() 257 | if (rlang::is_call(x) || rlang::is_expression(x)) x <- eval(x) 258 | x 259 | } 260 | 261 | writing_files_folders <- function(selected_template, path, 262 | overwrite, path_data, git, renv) { 263 | # creating the base project folder ------------------------------------------- 264 | if (!dir.exists(path)) { 265 | dir.create(path, recursive = TRUE) 266 | cli::cli_alert_success("Writing folder {.file {path}}") 267 | } 268 | 269 | # symbolic link text ---------------------------------------------------------- 270 | # if folder location of data provided creating symbolic link text 271 | symbolic_link <- 272 | ifelse( 273 | !is.null(path_data), 274 | glue::glue('starter::create_symlink(to = "{normalizePath(path_data, winslash = \"/\", mustWork = FALSE)}")'), 275 | 'starter::create_symlink(to = "")' 276 | ) 277 | folder_name <- basename(path) 278 | 279 | # creating project folder(s) ------------------------------------------------- 280 | selected_template %>% 281 | map_chr("filename") %>% 282 | dirname() %>% 283 | discard(~. == ".") %>% 284 | unique() %>% 285 | walk( 286 | function(.x) { 287 | if (!dir.exists(file.path(path, .x))) { 288 | dir.create(file.path(path, .x), recursive = TRUE) 289 | cli::cli_alert_success("Creating {.file {file.path(path, .x)}}") 290 | } 291 | } 292 | ) 293 | 294 | # tibble of each file in template -------------------------------------------- 295 | df_files <- 296 | dplyr::tibble(file_abbrv = names(selected_template)) %>% 297 | dplyr::rowwise() %>% 298 | dplyr::mutate( 299 | filename = selected_template[[.data$file_abbrv]]$filename, 300 | template_file_path = selected_template[[.data$file_abbrv]]$template_filename, 301 | glue = selected_template[[.data$file_abbrv]]$glue, 302 | file_exists = file.exists(file.path(.env$path, .data$filename)) 303 | ) 304 | df_files$write_file <- 305 | seq_len(nrow(df_files)) %>% 306 | map_lgl( 307 | function(i) { 308 | if (!df_files$file_exists[i]) return(TRUE) 309 | if (isTRUE(overwrite)) return(TRUE) 310 | if (isFALSE(overwrite)) return(FALSE) 311 | if (!interactive()) return(FALSE) 312 | msg <- paste("{.file {df_files$filename[i]}} already exists.", 313 | "Would you like to overwrite it?") 314 | return(ui_yeah2(msg)) 315 | } 316 | ) 317 | 318 | # remove files we will not write --------------------------------------------- 319 | df_files <- df_files %>% dplyr::filter(.data$write_file) 320 | 321 | # writing template files to folder ------------------------------------------- 322 | walk( 323 | seq_len(nrow(df_files)), 324 | function(i) { 325 | # if glue file contents, importing as string, evaluating glue::glue, and writing to file 326 | if (df_files$glue[i]) { 327 | readLines(df_files$template_file_path[i]) %>% 328 | paste(collapse = "\n") %>% 329 | glue::glue(.open = "{{", .close = "}}") %>% 330 | writeLines(con = file.path(path, df_files$filename[i])) 331 | } 332 | # if just copying (no glue), copying file to project folder 333 | else { 334 | file.copy( 335 | from = df_files$template_file_path[i], 336 | to = file.path(path, df_files$filename[i]), 337 | overwrite = TRUE 338 | ) 339 | } 340 | } 341 | ) 342 | cli::cli_alert_success("Writing files {.val {df_files$filename}}") 343 | } 344 | 345 | initialise_git <- function(git, path) { 346 | # initializing git repo ------------------------------------------------------ 347 | if (isTRUE(git) && !is_git(path)) { 348 | cli::cli_alert_success("Initialising {.field Git} repo") 349 | # if there is an error setting up, printing note about the error 350 | tryCatch({ 351 | # Configure Git repository 352 | gert::git_init(path = path) 353 | }, 354 | error = function(e) { 355 | cli::cli_alert_danger( 356 | paste( 357 | "There was an error in {.code gert::git_init()} while\n", 358 | "initialising the Git repo.\n", 359 | "Have you installed Git and set it up?\n", 360 | "Refer to the book 'Happy Git and GitHub for the useR'\n", 361 | "for step-by-step instructions on getting started with Git." 362 | ) 363 | ) 364 | cli::cli_alert("{.url https://happygitwithr.com/install-git.html}") 365 | # setting git to FALSE as no git repo exists 366 | git <- FALSE 367 | }) 368 | } 369 | } 370 | 371 | copy_to_glue <- function(x) { 372 | map( 373 | x, 374 | ~switch( 375 | "copy" %in% names(.x), 376 | modifyList(.x, val = list(glue = !.x$copy, copy = NULL)) 377 | ) %||% .x 378 | ) 379 | } 380 | 381 | 382 | is_git <- function(path = ".") { 383 | dir.exists(path) && dir.exists(paths = file.path(path, ".git")) 384 | } 385 | 386 | has_rproj <- function(path) { 387 | files <- list.files(path = path) 388 | 389 | isTRUE(any(grepl(x = files, pattern = "\\.Rproj$"))) 390 | } 391 | -------------------------------------------------------------------------------- /R/create_symlink.R: -------------------------------------------------------------------------------- 1 | #' Establish symbolic link between folders 2 | #' 3 | #' The `starter_symlink()` function is an OS agnostic function that creates symbolic 4 | #' links between two folders. The function is, at its core, a wrapper for the 5 | #' `R.utils::createLink()` function with opinionated 6 | #' defaults. The function must be called in an environment where the working 7 | #' directory is known (e.g. using `*.Rproj`, `setwd()`, etc.). 8 | #' 9 | #' A symbolic link is a special kind of file that points to another file/folder. 10 | #' A symbolic link does not contain the data in the target file. It simply points 11 | #' to another entry somewhere in the file system. This allows symbolic links 12 | #' to link to directories or files on remote network locations. Depending 13 | #' on your operating system, a link may not establish if the originating 14 | #' path is a network drive. 15 | #' 16 | #' @param to target file or directory to which the shortcut should point to. 17 | #' @param name symbolic link folder name. Default folder name is `"secure_data"` 18 | #' @param ... arguments passed on to `R.utils::createLink()` 19 | #' @seealso [`R.utils::createLink()`] 20 | #' @export 21 | #' @author Daniel D. Sjoberg 22 | #' @returns NULL, Places the path or pathname to the link. 23 | #' @examplesIf interactive() 24 | #' # Using `starter_symlink()` to establish a symbolic link to a 25 | #' # mapped networked data folder. 26 | #' # The default name of the symlink folder is 'secure_data' 27 | #' create_symlink("O:/Outcomes/Project Folder/Data") 28 | create_symlink <- function(to, name = "secure_data", ...) { 29 | # checking inputs ------------------------------------------------------------ 30 | # checking folder name a string of length 1 31 | if (!rlang::is_string(name)) { 32 | cli::cli_alert_danger("Argument {.field {name}} must be a string of length one.") 33 | stopifnot(rlang::is_string(name)) 34 | } 35 | 36 | # checking if location is an existing folder 37 | if (dir.exists(name)) { 38 | cli::cli_alert_danger("{.file {name}} is an existing folder, and symbolic link cannot be placed.") 39 | stop() 40 | } 41 | 42 | # checking if a link/file already exists 43 | if (is.symlink(name) || file.exists(name)) { 44 | cli::cli_alert_danger("{.file {name}} is an existing symbolic link or file, and a new symbolic link cannot be placed.") 45 | cli::cli_alert_danger("Delete the file or update the {.field name} argument and re-run {.code create_symlink()}.") 46 | stop() 47 | } 48 | 49 | # checking to argument is a path --------------------------------------------- 50 | if (!isTRUE(dir.exists(to))) { 51 | cli::cli_alert_danger("{.file {to}} is not an existing directory path.") 52 | cli::cli_ul("Update the {.field to} argument and re-run {.code create_symlink()}.") 53 | stop() 54 | } 55 | 56 | # checking for networked drives on Windows ----------------------------------- 57 | # checking if working on Windows and trying to create symbolic link on mapped 58 | # drive this may cause problems on a windows machine 59 | msg <- NULL 60 | if (Sys.info()[["sysname"]] == "Windows") { 61 | # grabbing drive name of project folder 62 | drive_here <- substr(.find_project_root(), 1, 2) 63 | 64 | # getting list of mapped network drives 65 | drive_mapped <- 66 | system("net use", intern = TRUE) %>% # grabbing all mapped drives 67 | {regmatches(., gregexpr('[A-Z]:', text = .))} %>% # extracting the drive letter 68 | discard(rlang::is_empty) %>% # removing NAs 69 | setdiff("C:") %>% 70 | unlist() 71 | 72 | # saving message to print is warning or error occurs 73 | if(drive_here %in% drive_mapped) { 74 | msg <- paste( 75 | "It looks like you've attempted to save a symbolic link on a\n", 76 | "mapped network drive. This often causes issues when working in\n", 77 | "Windows. If you encounter an error, consider moving your GitHub\n", 78 | "repo to your local C: drive, and establishing the link there." 79 | ) 80 | } 81 | } 82 | 83 | # wrapping createLink -------------------------------------------------------- 84 | tryCatch( 85 | { 86 | R.utils::createLink(link = .find_project_root(name), target = to, ...) 87 | paste0("Symbolic link placed connecting {.file {name}} to\n", 88 | "{.file {to}}") %>% 89 | cli::cli_alert_success() 90 | }, 91 | error = function(e) { 92 | # displaying note about windows and symbolic links if error occurred 93 | if(!is.null(msg)) cli::cli_alert_danger(msg) 94 | stop(e) 95 | } 96 | ) 97 | 98 | invisible() 99 | } 100 | 101 | 102 | is.symlink <- function(path) isTRUE(nzchar(Sys.readlink(path), keepNA = TRUE)) 103 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Project templates 2 | #' 3 | #' The `project_templates` object defines the contents of the project 4 | #' templates used in `create_project()` and `use_file()`. 5 | #' 6 | #' @format A named list containing the project templates. 7 | #' @examples 8 | #' if (FALSE) { 9 | #' create_project( 10 | #' path = file.path(tempdir(), "Sjoberg New Project"), 11 | #' template = project_templates[["analysis"]] 12 | #' ) 13 | #' } 14 | "project_templates" 15 | -------------------------------------------------------------------------------- /R/starter-package.R: -------------------------------------------------------------------------------- 1 | #' @importFrom dplyr %>% 2 | #' @importFrom rlang %||% .data .env 3 | #' @keywords internal 4 | "_PACKAGE" 5 | 6 | # similar to usethis::ui_yeah(), but no usethis dep 7 | ui_yeah2 <- function(x, .envir = parent.frame()) { 8 | cli::cli_alert_warning(x, .envir = .envir) 9 | utils::menu(c("Yes", "No"), "") %>% 10 | {dplyr::case_when( 11 | . == 1L ~ TRUE, 12 | . == 2L ~ FALSE 13 | )} 14 | } 15 | 16 | # allowing for the use of the dot when piping 17 | utils::globalVariables(".") 18 | 19 | # The following block is used by usethis to automatically manage 20 | # roxygen namespace tags. Modify with care! 21 | ## usethis namespace: start 22 | ## usethis namespace: end 23 | NULL 24 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/R/sysdata.rda -------------------------------------------------------------------------------- /R/use_project_file.R: -------------------------------------------------------------------------------- 1 | #' Write a template file 2 | #' 3 | #' Rather than using `create_project()` to start a new project folder, you 4 | #' may use `use_project_file()` to write a single file from any project template. 5 | #' The functions `use_project_gitignore()` and `use_project_readme()` are shortcuts for 6 | #' `use_project_file("gitignore")` and `use_project_file("readme")`. 7 | #' 8 | #' @param name Name of file to write. Not sure of the files available to you? 9 | #' Run the function without specifying a name, and all files available within the 10 | #' template will print. 11 | #' @param filename Optional argument to specify the name of the file to be written. 12 | #' Paths/filename is relative to project base 13 | #' @param open If `TRUE`, opens the new file. 14 | #' @inheritParams create_project 15 | #' @name use_project_file 16 | #' @rdname use_project_file 17 | #' @seealso [`create_project()`] 18 | #' @seealso [Vignette for `create_project()`](https://www.danieldsjoberg.com/starter/articles/create_project.html) 19 | #' @export 20 | #' @returns NULL, places single template file in current working directory 21 | #' @examples 22 | #' # only run fn interactively, will place files in current working dir 23 | #' if (interactive()) { 24 | #' # create gitignore file 25 | #' use_project_file("gitignore") 26 | #' use_project_gitignore() 27 | #' 28 | #' # create README.md file 29 | #' use_project_file("readme") 30 | #' use_project_readme() 31 | #' } 32 | 33 | use_project_file <- function(name = NULL, filename = NULL, 34 | template = NULL, open = interactive()) { 35 | # import template ------------------------------------------------------------ 36 | path <- .find_project_root() 37 | template <- evaluate_project_template(template, path, git = FALSE, renv = FALSE) 38 | 39 | # checking name is in selected template 40 | if (is.null(name) || !name %in% names(template)) { 41 | paste("Argument `name=` is not valid. Must be one of\n", 42 | paste(shQuote(names(template)), collapse = ", ")) %>% 43 | stop(call. = FALSE) 44 | } 45 | 46 | # only keeping file selected 47 | template <- template[name] 48 | 49 | # if file already exists, prompt user for new name 50 | filename <- filename %||% template[[name]]$filename 51 | 52 | if (file.exists(file.path(path, filename)) && interactive()) { 53 | cli::cli_alert_danger("File {.file {filename}} already exists.") 54 | filename <- readline("Please supply a new file name including extension [return to quit]. ") 55 | if (filename == "") { 56 | cli::cli_alert_danger("Aborting.") 57 | return(invisible()) 58 | } 59 | } 60 | 61 | # replace the output filename in the template 62 | template[[name]]$filename <- filename 63 | 64 | # writing file --------------------------------------------------------------- 65 | writing_files_folders( 66 | selected_template = template, 67 | path = path, 68 | overwrite = NA, 69 | path_data = NULL 70 | ) 71 | 72 | # opening new file ----------------------------------------------------------- 73 | if (open && file.exists(template[[name]][["filename"]])) { 74 | utils::file.edit(template[[name]][["filename"]]) 75 | } 76 | 77 | return(invisible()) 78 | } 79 | 80 | #' @rdname use_project_file 81 | #' @export 82 | use_project_gitignore <- function(filename = NULL, template = NULL) { 83 | use_project_file(name = "gitignore", filename = filename, template = template) 84 | } 85 | 86 | #' @rdname use_project_file 87 | #' @export 88 | use_project_readme <- function(filename = NULL, template = NULL) { 89 | use_project_file(name = "readme", filename = filename, template = template) 90 | } 91 | 92 | -------------------------------------------------------------------------------- /R/utils-keepers.R: -------------------------------------------------------------------------------- 1 | # NOTE!!! 2 | # This requires map_lgl() which requries map() 3 | 4 | is_empty <- function(x) length(x) == 0 5 | 6 | # keep <- function(.x, .p, ...) { 7 | # .x[map_lgl(.x, .p, ...)] 8 | # } 9 | 10 | discard <- function(.x, .p, ...) { 11 | .x[!map_lgl(.x, .p, ...)] 12 | } 13 | 14 | compact <- function(.x, .p=identity) { 15 | discard(.x, function(x) is_empty(.p(x))) 16 | } 17 | -------------------------------------------------------------------------------- /R/utils-mappers.R: -------------------------------------------------------------------------------- 1 | # NOTE: At the bottom of this source file show the equivalents to purrr mappers 2 | # 3 | # NOTE these aren't 100% equivalent to the purrr mappers but cover very common use-cases 4 | # 5 | # NOTE formula function (e.g. ~{}) are 100% supported 6 | # 7 | # NOTE: THESE DO NOT SUPPORT list EXTRACTORS 8 | 9 | set_names <- function(object = nm, nm) { 10 | names(object) <- nm 11 | object 12 | } 13 | 14 | map <- function(.x, .f, ..., .default) { 15 | 16 | default_exists <- !missing(.default) 17 | 18 | if (inherits(.f, "formula")) { 19 | .body <- dimnames(attr(stats::terms(.f), "factors"))[[1]] 20 | .f <- function(.x, . = .x) {} 21 | body(.f) <- as.expression(parse(text=.body)) 22 | } 23 | 24 | nm <- names(.x) 25 | 26 | if (inherits(.f, "function")) { 27 | 28 | lapply(.x, function(x) { 29 | res <- .f(x, ...) 30 | if ((length(res) == 0) & default_exists) res <- .default 31 | res 32 | }) -> out 33 | 34 | } else if (is.numeric(.f) | is.character(.f)) { 35 | 36 | lapply(.x, function(x) { 37 | res <- try(x[[.f]], silent = TRUE) 38 | if (inherits(res, "try-error")) res <- NULL 39 | if ((length(res) == 0) & default_exists) res <- .default 40 | res 41 | }) -> out 42 | 43 | } 44 | 45 | if (length(nm) > 0) out <- set_names(out, nm) 46 | 47 | out 48 | 49 | } 50 | 51 | # map2 <- function(.x, .y, .f, ..., .default) { 52 | # 53 | # default_exists <- !missing(.default) 54 | # 55 | # if (inherits(.f, "formula")) { 56 | # .body <- dimnames(attr(stats::terms(.f), "factors"))[[1]] 57 | # .f <- function(.x, .y, . = .x) {} 58 | # body(.f) <- as.expression(parse(text=.body)) 59 | # } 60 | # 61 | # if (inherits(.f, "function")) { 62 | # mapply( 63 | # function(x, ...) { 64 | # res <- .f(x, ...) 65 | # if ((length(res) == 0) & default_exists) res <- .default 66 | # res 67 | # }, 68 | # .x, .y, 69 | # ..., 70 | # SIMPLIFY=FALSE, USE.NAMES=FALSE 71 | # ) 72 | # } 73 | # 74 | # } 75 | 76 | map_chr <- function(.x, .f, ..., .default) { 77 | nm <- names(.x) 78 | out <- as.character((map(.x, .f, ..., .default = .default))) 79 | if (length(nm) > 0) set_names(out, nm) else out 80 | } 81 | 82 | # map2_chr <- function(.x, .y, .f, ..., .default) { 83 | # as.character(unlist(map2(.x, .y, .f, ..., .default = .default))) 84 | # } 85 | 86 | map_lgl <- function(.x, .f, ..., .default) { 87 | nm <- names(.x) 88 | out <- as.logical(unlist(map(.x, .f, ..., .default = .default))) 89 | if (length(nm) > 0) set_names(out, nm) else out 90 | } 91 | 92 | # map2_lgl <- function(.x, .y, .f, ..., .default) { 93 | # as.logical(unlist(map2(.x, .y, .f, ..., .default = .default))) 94 | # } 95 | 96 | # map_dbl <- function(.x, .f, ..., .default) { 97 | # nm <- names(.x) 98 | # out <- as.double(unlist(map(.x, .f, ..., .default = .default))) 99 | # if (length(nm) > 0) set_names(out, nm) else out 100 | # } 101 | 102 | # map2_dbl <- function(.x, .y, .f, ..., .default) { 103 | # as.double(unlist(map2(.x, .y, .f, ..., .default = .default))) 104 | # } 105 | 106 | # map_int <- function(.x, .f, ..., .default) { 107 | # nm <- names(.x) 108 | # out <- as.integer(unlist(map(.x, .f, ..., .default = .default))) 109 | # if (length(nm) > 0) set_names(out, nm) else out 110 | # } 111 | 112 | # map2_int <- function(.x, .y, .f, ..., .default) { 113 | # as.integer(unlist(map2(.x, .y, .f, ..., .default = .default))) 114 | # } 115 | 116 | 117 | # map_df <- function(.x, .f, ..., .id = NULL) { 118 | # 119 | # res <- map(.x, .f, ...) 120 | # out <- bind_rows(res, .id=.id) 121 | # out 122 | # 123 | # } 124 | # 125 | # map_dfr <- map_df 126 | # 127 | # map_dfc <- function(.x, .f, ...) { 128 | # 129 | # res <- map(.x, .f, ...) 130 | # out <- bind_cols(res) 131 | # out 132 | # 133 | # } 134 | # 135 | # map2_df <- function(.x, .y, .f, ..., .id=NULL) { 136 | # 137 | # res <- map2(.x, .y, .f, ...) 138 | # out <- bind_rows(res, .id = .id) 139 | # out 140 | # 141 | # } 142 | # 143 | # 144 | # map2_dfc <- function(.x, .y, .f, ...) { 145 | # 146 | # res <- map2(.x, .y, .f, ...) 147 | # out <- bind_cols(res) 148 | # out 149 | # 150 | # } 151 | # 152 | # # this has limitations and is more like 75% of dplyr::bind_rows() 153 | # # this is also orders of magnitude slower than dplyr::bind_rows() 154 | # bind_rows <- function(..., .id = NULL) { 155 | # 156 | # res <- list(...) 157 | # 158 | # if (length(res) == 1) res <- res[[1]] 159 | # 160 | # cols <- unique(unlist(lapply(res, names), use.names = FALSE)) 161 | # 162 | # if (!is.null(.id)) { 163 | # inthere <- cols[.id %in% cols] 164 | # if (length(inthere) > 0) { 165 | # .id <- make.unique(c(inthere, .id))[2] 166 | # } 167 | # } 168 | # 169 | # id_vals <- if (is.null(names(res))) 1:length(res) else names(res) 170 | # 171 | # saf <- default.stringsAsFactors() 172 | # options(stringsAsFactors = FALSE) 173 | # on.exit(options(stringsAsFactors = saf)) 174 | # 175 | # idx <- 1 176 | # do.call( 177 | # rbind.data.frame, 178 | # lapply(res, function(.x) { 179 | # x_names <- names(.x) 180 | # moar_names <- setdiff(cols, x_names) 181 | # if (length(moar_names) > 0) { 182 | # for (i in 1:length(moar_names)) { 183 | # .x[[moar_names[i]]] <- rep(NA, length(.x[[1]])) 184 | # } 185 | # } 186 | # if (!is.null(.id)) { 187 | # .x[[.id]] <- id_vals[idx] 188 | # idx <<- idx + 1 189 | # } 190 | # .x 191 | # }) 192 | # ) -> out 193 | # 194 | # rownames(out) <- NULL 195 | # 196 | # class(out) <- c("tbl_df", "tbl", "data.frame") 197 | # 198 | # out 199 | # 200 | # } 201 | # 202 | # bind_cols <- function(...) { 203 | # 204 | # res <- list(...) 205 | # 206 | # row_mismatch <- lapply(res, nrow) != nrow(res[[1]]) 207 | # 208 | # if (any(row_mismatch)) { 209 | # first_mismatch_pos <- which(row_mismatch)[1] 210 | # stop(paste0("Argument ", first_mismatch_pos, 211 | # " must be length ", nrow(res[[1]]), 212 | # ", not ", nrow(res[[first_mismatch_pos]]))) 213 | # } 214 | # 215 | # if (length(res) == 1) res <- res[[1]] 216 | # 217 | # col_names <- unlist(lapply(res, names), use.names = FALSE) 218 | # col_names <- make.unique(col_names, sep = "") 219 | # 220 | # saf <- default.stringsAsFactors() 221 | # options(stringsAsFactors = FALSE) 222 | # on.exit(options(stringsAsFactors = saf)) 223 | # 224 | # out <- do.call(cbind.data.frame, res) 225 | # 226 | # names(out) <- col_names 227 | # rownames(out) <- NULL 228 | # 229 | # class(out) <- c("tbl_df", "tbl", "data.frame") 230 | # 231 | # out 232 | # 233 | # } 234 | 235 | -------------------------------------------------------------------------------- /R/utils-project_root.R: -------------------------------------------------------------------------------- 1 | .find_project_root <- function(...) { 2 | # potential roots are the location of the RStudio Proj, git root, or the R package root 3 | potential_roots <- 4 | c( 5 | tryCatch(rprojroot::find_root(rprojroot::is_rstudio_project), error = function(e) NA_character_), 6 | tryCatch(rprojroot::find_root(rprojroot::is_vcs_root), error = function(e) NA_character_), 7 | tryCatch(rprojroot::find_root(rprojroot::is_r_package), error = function(e) NA_character_), 8 | tryCatch(rprojroot::find_root(rprojroot::is_remake_project), error = function(e) NA_character_), 9 | tryCatch(rprojroot::find_root(rprojroot::is_drake_project), error = function(e) NA_character_), 10 | tryCatch(rprojroot::find_root(rprojroot::is_pkgdown_project), error = function(e) NA_character_), 11 | tryCatch(rprojroot::find_root(rprojroot::is_projectile_project), error = function(e) NA_character_), 12 | tryCatch(rprojroot::find_root(rprojroot::is_testthat), error = function(e) NA_character_) 13 | ) %>% 14 | stats::na.omit() 15 | 16 | # keep longest directory as the root 17 | root <- potential_roots[nchar(potential_roots) == max(nchar(potential_roots))][1] 18 | 19 | fs::path(root, ...) 20 | } 21 | -------------------------------------------------------------------------------- /R/utils-safely.R: -------------------------------------------------------------------------------- 1 | # Less cool counterparts to purrr's side-effect capture-rs 2 | # 3 | # Most of the helper functions are 100% from output.R in purrr repo 4 | # 5 | # @param quiet Hide errors (`TRUE`, the default), or display them 6 | # as they occur? 7 | # @param otherwise Default value to use when an error occurs. 8 | # 9 | # @return `safely`: wrapped function instead returns a list with 10 | # components `result` and `error`. One value is always `NULL`. 11 | # 12 | # `quietly`: wrapped function instead returns a list with components 13 | # `result`, `output`, `messages` and `warnings`. 14 | # 15 | # `possibly`: wrapped function uses a default value (`otherwise`) 16 | # whenever an error occurs. 17 | # safely <- function(.f, otherwise = NULL, quiet = TRUE) { 18 | # function(...) capture_error(.f(...), otherwise, quiet) 19 | # } 20 | 21 | # quietly <- function(.f) { 22 | # function(...) capture_output(.f(...)) 23 | # } 24 | # 25 | # possibly <- function(.f, otherwise, quiet = TRUE) { 26 | # force(otherwise) 27 | # function(...) { 28 | # tryCatch(.f(...), 29 | # error = function(e) { 30 | # if (!quiet) 31 | # message("Error: ", e$message) 32 | # otherwise 33 | # }, 34 | # interrupt = function(e) { 35 | # stop("Terminated by user", call. = FALSE) 36 | # } 37 | # ) 38 | # } 39 | # } 40 | # 41 | # capture_error <- function(code, otherwise = NULL, quiet = TRUE) { 42 | # tryCatch( 43 | # list(result = code, error = NULL), 44 | # error = function(e) { 45 | # if (!quiet) 46 | # message("Error: ", e$message) 47 | # 48 | # list(result = otherwise, error = e) 49 | # }, 50 | # interrupt = function(e) { 51 | # stop("Terminated by user", call. = FALSE) 52 | # } 53 | # ) 54 | # } 55 | # 56 | # capture_output <- function(code) { 57 | # warnings <- character() 58 | # wHandler <- function(w) { 59 | # warnings <<- c(warnings, w$message) 60 | # invokeRestart("muffleWarning") 61 | # } 62 | # 63 | # messages <- character() 64 | # mHandler <- function(m) { 65 | # messages <<- c(messages, m$message) 66 | # invokeRestart("muffleMessage") 67 | # } 68 | # 69 | # temp <- file() 70 | # sink(temp) 71 | # on.exit({ 72 | # sink() 73 | # close(temp) 74 | # }) 75 | # 76 | # result <- withCallingHandlers( 77 | # code, 78 | # warning = wHandler, 79 | # message = mHandler 80 | # ) 81 | # 82 | # output <- paste0(readLines(temp, warn = FALSE), collapse = "\n") 83 | # 84 | # list( 85 | # result = result, 86 | # output = output, 87 | # warnings = warnings, 88 | # messages = messages 89 | # ) 90 | # } 91 | -------------------------------------------------------------------------------- /R/utils-walkers.R: -------------------------------------------------------------------------------- 1 | # NOTE these aren't 100% equivalent to the purrr walkers but cover very common use-cases 2 | # 3 | # NOTE formula function (e.g. ~{}) are 100% supported 4 | 5 | # walk(LETTERS, ~cat(tolower(.x))) 6 | walk <- function(.x, .f, ...) { 7 | 8 | if (inherits(.f, "formula")) { 9 | .body <- dimnames(attr(stats::terms(.f), "factors"))[[1]] 10 | .f <- function(.x, . = .x) {} 11 | body(.f) <- as.expression(parse(text=.body)) 12 | } 13 | 14 | if (inherits(.f, "function")) { 15 | for (idx in seq_along(.x)) .f(.x[[idx]], ...) 16 | } else { 17 | stop("I'm not sure indexing by name or number makes sense for walk().") 18 | } 19 | 20 | invisible(.x) 21 | 22 | } 23 | 24 | # walk2(LETTERS, letters, ~cat(tolower(.x), rep(toupper(.y), 4), sep="")) 25 | walk2 <- function(.x, .y, .f, ...) { 26 | 27 | if (inherits(.f, "formula")) { 28 | .body <- dimnames(attr(stats::terms(.f), "factors"))[[1]] 29 | .f <- function(.x, .y, . = .x) {} 30 | body(.f) <- as.expression(parse(text=.body)) 31 | } 32 | 33 | if (inherits(.f, "function")) { 34 | for (idx in seq_along(.x)) .f(.x[[idx]], .y[[idx]], ...) 35 | } 36 | 37 | invisible(.x) 38 | 39 | } 40 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | ```{r, include = FALSE} 7 | knitr::opts_chunk$set( 8 | collapse = TRUE, 9 | comment = "#>", 10 | fig.path = "man/figures/README-", 11 | out.width = "100%" 12 | ) 13 | ``` 14 | 15 | # starter 16 | 17 | 18 | [![R-CMD-check](https://github.com/ddsjoberg/starter/workflows/R-CMD-check/badge.svg)](https://github.com/ddsjoberg/starter/actions) 19 | [![Codecov test coverage](https://codecov.io/gh/ddsjoberg/starter/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ddsjoberg/starter?branch=main) 20 | [![CRAN status](https://www.r-pkg.org/badges/version/starter)](https://CRAN.R-project.org/package=starter) 21 | 22 | 23 | The **starter** package provides a toolkit for starting new projects. 24 | 25 | ## Installation 26 | 27 | Install {starter} from CRAN with: 28 | 29 | ``` r 30 | install.packages("starter") 31 | ``` 32 | 33 | Install the development version of {starter} from [GitHub](https://github.com/ddsjoberg/starter) with: 34 | 35 | ``` r 36 | # install.packages('devtools') 37 | devtools::install_github("ddsjoberg/starter") 38 | ``` 39 | ## Example 40 | 41 | ```{r} 42 | library(starter) 43 | 44 | create_project( 45 | path = fs::path(tempdir(), "My Project Folder"), 46 | open = FALSE # don't open project in new RStudio session 47 | ) 48 | ``` 49 | 50 | ## Example Templates 51 | 52 | Check out examples of starter templates currently being used. 53 | 54 | ```r 55 | devtools::install_github("ddsjoberg/bstfun") 56 | create_project( 57 | path = fs::path(tempdir(), "My Project Folder"), 58 | template = bstfun::project_templates[["hot"]] 59 | ) 60 | 61 | create_project( 62 | path = fs::path(tempdir(), "My Project Folder"), 63 | template = bstfun::project_templates[["default"]] 64 | ) 65 | ``` 66 | ## Code of Conduct 67 | 68 | Please note that the starter project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. 69 | 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # starter 5 | 6 | 7 | 8 | [![R-CMD-check](https://github.com/ddsjoberg/starter/workflows/R-CMD-check/badge.svg)](https://github.com/ddsjoberg/starter/actions) 9 | [![Codecov test 10 | coverage](https://codecov.io/gh/ddsjoberg/starter/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ddsjoberg/starter?branch=main) 11 | [![CRAN 12 | status](https://www.r-pkg.org/badges/version/starter)](https://CRAN.R-project.org/package=starter) 13 | 14 | 15 | The **starter** package provides a toolkit for starting new projects. 16 | 17 | ## Installation 18 | 19 | Install {starter} from CRAN with: 20 | 21 | ``` r 22 | install.packages("starter") 23 | ``` 24 | 25 | Install the development version of {starter} from 26 | [GitHub](https://github.com/ddsjoberg/starter) with: 27 | 28 | ``` r 29 | # install.packages('devtools') 30 | devtools::install_github("ddsjoberg/starter") 31 | ``` 32 | 33 | ## Example 34 | 35 | ``` r 36 | library(starter) 37 | 38 | create_project( 39 | path = fs::path(tempdir(), "My Project Folder"), 40 | open = FALSE # don't open project in new RStudio session 41 | ) 42 | #> ✔ Using "Default Project Template" template 43 | #> ✔ Writing folder '/var/folders/6f/gdjf_vxj2wl3jhmxdkd1hd_w0000gn/T/RtmpTUywzl/My Project Folder' 44 | #> ✔ Writing files "README.md", ".gitignore", "My Project Folder.Rproj", and ".Rprofile" 45 | #> ✔ Initialising Git repo 46 | #> ✔ Initialising renv project 47 | #> - Lockfile written to "/private/var/folders/6f/gdjf_vxj2wl3jhmxdkd1hd_w0000gn/T/RtmpTUywzl/My Project Folder/renv.lock". 48 | #> - renv infrastructure has been generated for project "/private/var/folders/6f/gdjf_vxj2wl3jhmxdkd1hd_w0000gn/T/RtmpTUywzl/My Project Folder". 49 | ``` 50 | 51 | ## Example Templates 52 | 53 | Check out examples of starter templates currently being used. 54 | 55 | ``` r 56 | devtools::install_github("ddsjoberg/bstfun") 57 | create_project( 58 | path = fs::path(tempdir(), "My Project Folder"), 59 | template = bstfun::project_templates[["hot"]] 60 | ) 61 | 62 | create_project( 63 | path = fs::path(tempdir(), "My Project Folder"), 64 | template = bstfun::project_templates[["default"]] 65 | ) 66 | ``` 67 | 68 | ## Code of Conduct 69 | 70 | Please note that the starter project is released with a [Contributor 71 | Code of 72 | Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). 73 | By contributing to this project, you agree to abide by its terms. 74 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: http://www.danieldsjoberg.com/starter/ 2 | 3 | template: 4 | params: 5 | bootswatch: journal 6 | development: 7 | mode: auto 8 | version_label: default 9 | 10 | authors: 11 | Daniel D. Sjoberg: 12 | href: "http://www.danieldsjoberg.com/" 13 | 14 | navbar: 15 | type: default 16 | left: 17 | - icon: fa-home 18 | href: index.html 19 | - text: Reference 20 | href: reference/index.html 21 | - text: Getting Started 22 | href: articles/create_project.html 23 | - text: News 24 | href: news/index.html 25 | right: 26 | - icon: fa-github fa-lg 27 | href: https://github.com/ddsjoberg/starter/ 28 | url: http://www.danieldsjoberg.com/starter/ 29 | 30 | reference: 31 | - contents: 32 | - create_project 33 | - starts_with("use_") 34 | - create_symlink 35 | - project_templates 36 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors √ | 0 warnings √ | 0 note √ 4 | 5 | ## Additional Comments 6 | 7 | Thank you for your time 8 | -------------------------------------------------------------------------------- /data-raw/analysis_project_templates.R: -------------------------------------------------------------------------------- 1 | analysis_project_template <- 2 | list( 3 | readme = rlang::expr(list( 4 | template_filename = fs::path_package("project_templates/default_readme.md", package = "starter"), 5 | filename = "README.md", 6 | copy = FALSE 7 | )), 8 | gitignore = rlang::expr(list( 9 | template_filename = fs::path_package("project_templates/default_gitignore.txt", package = "starter"), 10 | filename = ".gitignore", 11 | copy = TRUE 12 | )), 13 | rproj = rlang::expr(list( 14 | template_filename = fs::path_package("project_templates/default_rproj.Rproj", package = "starter"), 15 | filename = glue::glue("_rstudio_project.Rproj"), 16 | copy = TRUE 17 | )), 18 | setup = rlang::expr(list( 19 | template_filename = fs::path_package("project_templates/analysis_template/setup.Rmd", package = "starter"), 20 | filename = glue::glue("scripts/10-setup_{folder_first_word}.Rmd"), 21 | copy = FALSE 22 | )), 23 | analysis = rlang::expr(list( 24 | template_filename = fs::path_package("project_templates/analysis_template/analysis.Rmd", package = "starter"), 25 | filename = glue::glue("scripts/20-analysis_{folder_first_word}.Rmd"), 26 | copy = FALSE 27 | )), 28 | report = rlang::expr(list( 29 | template_filename = fs::path_package("project_templates/analysis_template/report.Rmd", package = "starter"), 30 | filename = glue::glue("scripts/30-report_{folder_first_word}.Rmd"), 31 | copy = FALSE 32 | )), 33 | doc_template = rlang::expr(list( 34 | template_filename = fs::path_package("project_templates/analysis_template/doc_template.docx", package = "starter"), 35 | filename = "scripts/templates/doc_template.docx", 36 | copy = TRUE 37 | )), 38 | references = rlang::expr(list( 39 | template_filename = fs::path_package("project_templates/analysis_template/references.bib", package = "starter"), 40 | filename = glue::glue("scripts/templates/references.bib"), 41 | copy = TRUE 42 | )), 43 | derived_vars = rlang::expr(list( 44 | template_filename = fs::path_package("project_templates/analysis_template/derived_variables.xlsx", package = "starter"), 45 | filename = glue::glue("scripts/derived_variables.xlsx"), 46 | copy = TRUE 47 | )), 48 | sap = rlang::expr(list( 49 | template_filename = fs::path_package("project_templates/analysis_template/sap.docx", package = "starter"), 50 | filename = glue::glue("SAP - {folder_name}.docx"), 51 | copy = TRUE 52 | )), 53 | # only add Rprofile if renv was used 54 | rprofile = 55 | rlang::expr(switch(renv, 56 | list( 57 | template_filename = 58 | fs::path_package(package = "starter", "project_templates/default_rprofile.R"), 59 | filename = glue::glue(".Rprofile"), 60 | glue = TRUE 61 | ) 62 | )) 63 | ) 64 | -------------------------------------------------------------------------------- /data-raw/hex/starter-hex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/data-raw/hex/starter-hex.png -------------------------------------------------------------------------------- /data-raw/project_templates.R: -------------------------------------------------------------------------------- 1 | ## code to prepare project template goes here 2 | 3 | # default template ------------------------------------------------------------- 4 | default_project_template <- 5 | list( 6 | readme = rlang::expr(list( 7 | template_filename = 8 | fs::path_package(package = "starter", "project_templates/default_readme.md"), 9 | filename = "README.md", 10 | glue = TRUE 11 | )), 12 | gitignore = rlang::expr(list( 13 | template_filename = 14 | fs::path_package(package = "starter", "project_templates/default_gitignore.txt"), 15 | filename = ".gitignore", 16 | glue = FALSE 17 | )), 18 | rproj = rlang::expr(list( 19 | template_filename = 20 | fs::path_package(package = "starter", "project_templates/default_rproj.Rproj"), 21 | filename = glue::glue("{folder_name}.Rproj"), 22 | glue = FALSE 23 | )), 24 | # only add Rprofile if renv was used 25 | rprofile = 26 | rlang::expr(switch( 27 | renv, 28 | list( 29 | template_filename = 30 | fs::path_package(package = "starter", 31 | "project_templates/default_rprofile.R"), 32 | filename = glue::glue(".Rprofile"), 33 | glue = TRUE 34 | ) 35 | )) 36 | ) 37 | attr(default_project_template, "label") <- "Default Project Template" 38 | 39 | 40 | # analysis template ------------------------------------------------------------ 41 | analysis_project_template <- 42 | c(default_project_template, 43 | list( 44 | setup = rlang::expr(list( 45 | template_filename = fs::path_package("project_templates/analysis_template/setup.Rmd", package = "starter"), 46 | filename = glue::glue("scripts/10-setup_{folder_first_word}.Rmd"), 47 | copy = FALSE 48 | )), 49 | analysis = rlang::expr(list( 50 | template_filename = fs::path_package("project_templates/analysis_template/analysis.Rmd", package = "starter"), 51 | filename = glue::glue("scripts/20-analysis_{folder_first_word}.Rmd"), 52 | copy = FALSE 53 | )), 54 | report = rlang::expr(list( 55 | template_filename = fs::path_package("project_templates/analysis_template/report.Rmd", package = "starter"), 56 | filename = glue::glue("scripts/30-report_{folder_first_word}.Rmd"), 57 | copy = FALSE 58 | )), 59 | doc_template = rlang::expr(list( 60 | template_filename = fs::path_package("project_templates/analysis_template/doc_template.docx", package = "starter"), 61 | filename = "scripts/templates/doc_template.docx", 62 | copy = TRUE 63 | )), 64 | references = rlang::expr(list( 65 | template_filename = fs::path_package("project_templates/analysis_template/references.bib", package = "starter"), 66 | filename = glue::glue("scripts/templates/references.bib"), 67 | copy = TRUE 68 | )), 69 | derived_vars = rlang::expr(list( 70 | template_filename = fs::path_package("project_templates/analysis_template/derived_variables.xlsx", package = "starter"), 71 | filename = glue::glue("scripts/derived_variables.xlsx"), 72 | copy = TRUE 73 | )), 74 | sap = rlang::expr(list( 75 | template_filename = fs::path_package("project_templates/analysis_template/sap.docx", package = "starter"), 76 | filename = glue::glue("SAP - {folder_name}.docx"), 77 | copy = TRUE 78 | )) 79 | ) 80 | ) 81 | attr(analysis_project_template, "label") <- "Analysis Project Template" 82 | 83 | 84 | 85 | 86 | # save templates --------------------------------------------------------------- 87 | project_templates <- list() 88 | project_templates[["default"]] <- default_project_template 89 | project_templates[["analysis"]] <- analysis_project_template 90 | usethis::use_data(project_templates, overwrite = TRUE, internal = FALSE) 91 | -------------------------------------------------------------------------------- /data/project_templates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/data/project_templates.rda -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | CMD 2 | Codecov 3 | ORCID 4 | RStudio 5 | Rmarkdown 6 | initialise 7 | initialised 8 | pre 9 | prefs 10 | renv 11 | repo 12 | rstudio 13 | rstudioapi 14 | subfolder 15 | subfolders 16 | tibble 17 | -------------------------------------------------------------------------------- /inst/project_templates/analysis_template/analysis.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Analysis" 3 | date: "Last Updated: `r format(Sys.Date(), format = '%B %d, %Y')`" 4 | output: 5 | html_document: 6 | toc: true 7 | toc_float: true 8 | toc_depth: 2 9 | --- 10 | 11 | ```{r setup, include=FALSE} 12 | knitr::opts_chunk$set(echo = TRUE) 13 | 14 | set.seed({{format(Sys.Date(), format = "%Y%m%d")}}) 15 | ``` 16 | 17 | # Analytic Data Import 18 | 19 | ```{r import} 20 | library(gtsummary); library(tidyverse) 21 | 22 | # setting and gtsummary theme 23 | theme_gtsummary_compact() 24 | 25 | # importing master analytic data set 26 | df_main <- readRDS(file = here::here("secure_data", "df_main.Rds")) 27 | ``` 28 | 29 | 30 | # Analysis 31 | 32 | ```{r analysis1} 33 | 34 | ``` 35 | 36 | # Save Results 37 | 38 | ```{r save} 39 | # list result objects here. save only those needed for the final report 40 | save( 41 | df_results, gts_table1, 42 | file = here::here("secure_data", "results.Rdata") 43 | ) 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /inst/project_templates/analysis_template/derived_variables.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/inst/project_templates/analysis_template/derived_variables.xlsx -------------------------------------------------------------------------------- /inst/project_templates/analysis_template/doc_template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/inst/project_templates/analysis_template/doc_template.docx -------------------------------------------------------------------------------- /inst/project_templates/analysis_template/references.bib: -------------------------------------------------------------------------------- 1 | % ------------------------------------------------------------------------------ 2 | % R and R Package references --------------------------------------------------- 3 | % List R packages in alphabetical order 4 | % If there is an article associated with the package, use that citation; 5 | % if not, then use `citation("pkg", auto=TRUE) |> toBibtex()` 6 | % ------------------------------------------------------------------------------ 7 | @Manual{r, 8 | title = {R: A Language and Environment for Statistical Computing}, 9 | author = {{R Core Team}}, 10 | organization = {R Foundation for Statistical Computing}, 11 | address = {Vienna, Austria}, 12 | year = {2021}, 13 | url = {https://www.R-project.org/}, 14 | } 15 | 16 | @Article{gtsummary, 17 | author = {Daniel D. Sjoberg and Karissa Whiting and Michael Curry and Jessica A. Lavery and Joseph Larmarange}, 18 | title = {{Reproducible Summary Tables with the gtsummary Package}}, 19 | journal = {{The R Journal}}, 20 | year = {2021}, 21 | url = {https://doi.org/10.32614/RJ-2021-053}, 22 | doi = {10.32614/RJ-2021-053}, 23 | volume = {13}, 24 | issue = {1}, 25 | pages = {570-580}, 26 | } 27 | 28 | @Article{tidyverse, 29 | title = {Welcome to the {tidyverse}}, 30 | author = {Hadley Wickham and Mara Averick and Jennifer Bryan and Winston Chang and Lucy D'Agostino McGowan and Romain François and Garrett Grolemund and Alex Hayes and Lionel Henry and Jim Hester and Max Kuhn and Thomas Lin Pedersen and Evan Miller and Stephan Milton Bache and Kirill Müller and Jeroen Ooms and David Robinson and Dana Paige Seidel and Vitalie Spinu and Kohske Takahashi and Davis Vaughan and Claus Wilke and Kara Woo and Hiroaki Yutani}, 31 | year = {2019}, 32 | journal = {Journal of Open Source Software}, 33 | volume = {4}, 34 | number = {43}, 35 | pages = {1686}, 36 | doi = {10.21105/joss.01686}, 37 | } 38 | -------------------------------------------------------------------------------- /inst/project_templates/analysis_template/report.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Report" 3 | date: "Last Updated: `r format(Sys.Date(), format = '%B %d, %Y')`" 4 | output: 5 | html_document: 6 | toc: true 7 | toc_float: true 8 | toc_depth: 2 9 | word_document: 10 | reference_docx: "`r here::here('templates/doc_template.docx')`" 11 | bibliography: "`r here::here('templates/references.bib')`" 12 | --- 13 | 14 | 15 | 16 | 17 | ```{r setup, include=FALSE} 18 | # set chunk defaults 19 | knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE) 20 | set.seed({{format(Sys.Date(), format = "%Y%m%d")}}) 21 | ``` 22 | 23 | ```{r import, include=FALSE} 24 | library(gtsummary); library(tidyverse) 25 | 26 | # setting and gtsummary theme 27 | theme_gtsummary_compact() 28 | 29 | # Import analysis result objects here 30 | results <- load(here::here("secure_data", "results.Rdata")) 31 | ``` 32 | 33 | ```{r inline_text, include=FALSE, echo=FALSE} 34 | # define complex inline-reporting objects here 35 | ``` 36 | 37 | # Methods 38 | 39 | Describe cohort and analytic methods here. 40 | 41 | All analyses were conducted using `r cite_r(pkgs = c("tidyverse", "gtsummary"), add_citation = TRUE)`. 42 | 43 | # Results 44 | 45 | Describe analytic results here. 46 | 47 | # Tables & Figures 48 | 49 | # References 50 | -------------------------------------------------------------------------------- /inst/project_templates/analysis_template/sap.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/inst/project_templates/analysis_template/sap.docx -------------------------------------------------------------------------------- /inst/project_templates/analysis_template/setup.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Initial Setup" 3 | date: "Last Updated: `r format(Sys.Date(), format = '%B %d, %Y')`" 4 | output: 5 | html_document: 6 | toc: true 7 | toc_float: true 8 | toc_depth: 2 9 | --- 10 | 11 | ```{r setup, include=FALSE} 12 | knitr::opts_chunk$set(echo = TRUE) 13 | 14 | set.seed({{format(Sys.Date(), format = "%Y%m%d")}}) 15 | ``` 16 | 17 | # Raw Data Import 18 | 19 | ```{r import} 20 | library(gtsummary); library(tidyverse) 21 | 22 | # setting and gtsummary theme 23 | theme_gtsummary_compact() 24 | 25 | # example code for importing excel file 26 | df_raw_data <- 27 | readxl::read_excel( 28 | path = here::here("secure_data", "Raw Data from PI.xlsx") 29 | ) %>% 30 | janitor::clean_names(case = "all_caps") %>% # uppercase col names 31 | mutate(across(where(lubridate::is.POSIXt), lubridate::as_date)) # use lubridates 32 | ``` 33 | 34 | # Create Master Analytic Data Set 35 | 36 | ```{r cleaning} 37 | 38 | ``` 39 | 40 | 41 | # Check Variables 42 | 43 | ```{r checking} 44 | 45 | ``` 46 | 47 | # Save Analytic Data 48 | 49 | ```{r save} 50 | # applying variable labels, and dropping raw variables 51 | df_main <- df_main %>% 52 | set_derived_variables(path = here::here("scripts/derived_variables.xlsx")) 53 | 54 | # overview of master analytic dataset 55 | skimr::skim(df_main) 56 | 57 | # saving master analytic data set 58 | saveRDS( 59 | object = df_main, 60 | file = here::here("secure_data", "df_main.Rds") 61 | ) 62 | ``` 63 | -------------------------------------------------------------------------------- /inst/project_templates/default_gitignore.txt: -------------------------------------------------------------------------------- 1 | # ignore R data files 2 | .Rproj.user 3 | .Rhistory 4 | *.RData 5 | *.rds 6 | .Ruserdata 7 | .Rapp.history 8 | .Rhistory.RData 9 | 10 | # Temporary files created by R markdown 11 | *.utf8.md 12 | *.knit.md 13 | 14 | # ignore other types of data files 15 | *.xlsx 16 | *.xls 17 | *.csv 18 | *.dta 19 | *.sas7bdat 20 | *.sav 21 | *.txt 22 | 23 | # ignore data folder/symbolic link/sensitive file 24 | data 25 | secure_data 26 | ext_data 27 | tmp 28 | env.json 29 | 30 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 31 | .httr-oauth 32 | 33 | # ignore misc files 34 | ~*.docx 35 | ~*.xlsx 36 | ~*.pptx 37 | ~*.tmp 38 | ~*.rtf 39 | Thumbs.db 40 | .DS_Store 41 | *.swp 42 | 43 | # renv folders 44 | renv/library/ 45 | renv/python/ 46 | renv/staging/ 47 | -------------------------------------------------------------------------------- /inst/project_templates/default_readme.md: -------------------------------------------------------------------------------- 1 | # {{folder_name}} 2 | 3 | # Symbolic Link to Secure Data 4 | {{symbolic_link}} 5 | -------------------------------------------------------------------------------- /inst/project_templates/default_rprofile.R: -------------------------------------------------------------------------------- 1 | 2 | # if renv project & it's bare, print message to record pkgs in R and Rmd scripts 3 | if (file.exists("renv.lock") && 4 | (!"renv" %in% utils::installed.packages()[, 1] || 5 | length(setdiff(names(renv:::renv_lockfile_read(file = "renv.lock")$Packages), "renv")) == 0L)) { 6 | message("* Your 'renv' project is not yet setup.") 7 | message("* Discover and record packages with `renv::install('rmarkdown'); renv::hydrate(); renv::snapshot()`") 8 | } 9 | -------------------------------------------------------------------------------- /inst/project_templates/default_rproj.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Yes 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | 17 | StripTrailingWhitespace: Yes 18 | -------------------------------------------------------------------------------- /man/create_project.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create_project.R 3 | \name{create_project} 4 | \alias{create_project} 5 | \title{Start a new project} 6 | \usage{ 7 | create_project( 8 | path, 9 | path_data = NULL, 10 | template = "default", 11 | git = TRUE, 12 | renv = TRUE, 13 | symlink = git, 14 | renv.settings = NULL, 15 | overwrite = NA, 16 | open = interactive() 17 | ) 18 | } 19 | \arguments{ 20 | \item{path}{A path. If it exists, it is used. If it does not exist, it is 21 | created.} 22 | 23 | \item{path_data}{A path. The directory where the secure data exist. Default is 24 | \code{NULL}. When supplied, a symbolic link to data folder will be created.} 25 | 26 | \item{template}{A project template. See 27 | \href{https://www.danieldsjoberg.com/starter/articles/create_project.html}{vignette} 28 | for details.} 29 | 30 | \item{git}{Logical indicating whether to create Git repository. Default is \code{TRUE} 31 | When \code{NA}, user will be prompted whether to initialise Git repo.} 32 | 33 | \item{renv}{Logical indicating whether to add renv to a project. 34 | Default is \code{TRUE}. When \code{NA} user is asked interactively for preference.} 35 | 36 | \item{symlink}{Logical indicating whether to place a symbolic link 37 | to the location in \verb{path_data=}. Default is to place the symbolic link 38 | if the project is a git repository.} 39 | 40 | \item{renv.settings}{A list of renv settings passed to \code{renv::scaffold(settings=)}} 41 | 42 | \item{overwrite}{Logical indicating whether to overwrite existing files 43 | if they exist. Options are 44 | \code{TRUE}, \code{FALSE}, and \code{NA} (aka ask interactively). Default is \code{NA}} 45 | 46 | \item{open}{Logical indicating whether to open new project in fresh RStudio 47 | session} 48 | } 49 | \value{ 50 | NULL, places project template in new or existing directory 51 | } 52 | \description{ 53 | Creates a directory with the essential files for 54 | a new project. The function can be used on existing project directories as well. 55 | Existing files will \emph{not} be overwritten; rather, the user will be prompted 56 | whether to replace the existing file with the template file. 57 | } 58 | \section{Personalized Template}{ 59 | 60 | Users can create a 61 | personalized project template. Check out the 62 | \href{https://www.danieldsjoberg.com/starter/articles/create_project.html}{vignette} 63 | for step by step instructions. 64 | } 65 | 66 | \examples{ 67 | \dontshow{if (pkgdown::in_pkgdown()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 68 | # specifying project folder location (folder does not yet exist) 69 | project_path <- file.path(tempdir(), "My Project Folder") 70 | 71 | # creating folder where secure data would be stored (typically will be a network drive) 72 | secure_data_path <- file.path(tempdir(), "secure_data") 73 | dir.create(secure_data_path) 74 | 75 | # creating new project folder 76 | create_project(project_path, path_data = secure_data_path) 77 | \dontshow{\}) # examplesIf} 78 | } 79 | \seealso{ 80 | \code{\link[=use_project_file]{use_project_file()}} 81 | 82 | \href{https://www.danieldsjoberg.com/starter/articles/create_project.html}{Vignette for \code{create_project()}} 83 | } 84 | \author{ 85 | Daniel D. Sjoberg 86 | } 87 | -------------------------------------------------------------------------------- /man/create_symlink.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create_symlink.R 3 | \name{create_symlink} 4 | \alias{create_symlink} 5 | \title{Establish symbolic link between folders} 6 | \usage{ 7 | create_symlink(to, name = "secure_data", ...) 8 | } 9 | \arguments{ 10 | \item{to}{target file or directory to which the shortcut should point to.} 11 | 12 | \item{name}{symbolic link folder name. Default folder name is \code{"secure_data"}} 13 | 14 | \item{...}{arguments passed on to \code{R.utils::createLink()}} 15 | } 16 | \value{ 17 | NULL, Places the path or pathname to the link. 18 | } 19 | \description{ 20 | The \code{starter_symlink()} function is an OS agnostic function that creates symbolic 21 | links between two folders. The function is, at its core, a wrapper for the 22 | \code{R.utils::createLink()} function with opinionated 23 | defaults. The function must be called in an environment where the working 24 | directory is known (e.g. using \verb{*.Rproj}, \code{setwd()}, etc.). 25 | } 26 | \details{ 27 | A symbolic link is a special kind of file that points to another file/folder. 28 | A symbolic link does not contain the data in the target file. It simply points 29 | to another entry somewhere in the file system. This allows symbolic links 30 | to link to directories or files on remote network locations. Depending 31 | on your operating system, a link may not establish if the originating 32 | path is a network drive. 33 | } 34 | \examples{ 35 | \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 36 | # Using `starter_symlink()` to establish a symbolic link to a 37 | # mapped networked data folder. 38 | # The default name of the symlink folder is 'secure_data' 39 | create_symlink("O:/Outcomes/Project Folder/Data") 40 | \dontshow{\}) # examplesIf} 41 | } 42 | \seealso{ 43 | \code{\link[R.utils:createLink]{R.utils::createLink()}} 44 | } 45 | \author{ 46 | Daniel D. Sjoberg 47 | } 48 | -------------------------------------------------------------------------------- /man/figures/README-pressure-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/man/figures/README-pressure-1.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddsjoberg/starter/3a02edbd6111cb7ef725687d58d848023c1b39a4/man/figures/logo.png -------------------------------------------------------------------------------- /man/project_templates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{project_templates} 5 | \alias{project_templates} 6 | \title{Project templates} 7 | \format{ 8 | A named list containing the project templates. 9 | } 10 | \usage{ 11 | project_templates 12 | } 13 | \description{ 14 | The \code{project_templates} object defines the contents of the project 15 | templates used in \code{create_project()} and \code{use_file()}. 16 | } 17 | \examples{ 18 | if (FALSE) { 19 | create_project( 20 | path = file.path(tempdir(), "Sjoberg New Project"), 21 | template = project_templates[["analysis"]] 22 | ) 23 | } 24 | } 25 | \keyword{datasets} 26 | -------------------------------------------------------------------------------- /man/starter-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/starter-package.R 3 | \docType{package} 4 | \name{starter-package} 5 | \alias{starter} 6 | \alias{starter-package} 7 | \title{starter: Starter Kit for New Projects} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | Get started with new projects by dropping a skeleton of a new project into a new or existing directory, initialise git repositories, and create reproducible environments with the 'renv' package. The package allows for dynamically named files, folders, file content, as well as the functionality to drop individual template files into existing projects. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://github.com/ddsjoberg/starter} 17 | \item \url{https://www.danieldsjoberg.com/starter/index.html} 18 | \item Report bugs at \url{https://github.com/ddsjoberg/starter/issues} 19 | } 20 | 21 | } 22 | \author{ 23 | \strong{Maintainer}: Daniel D. Sjoberg \email{danield.sjoberg@gmail.com} (\href{https://orcid.org/0000-0003-0862-2018}{ORCID}) 24 | 25 | Other contributors: 26 | \itemize{ 27 | \item Emily Vertosick [contributor] 28 | } 29 | 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/use_project_file.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/use_project_file.R 3 | \name{use_project_file} 4 | \alias{use_project_file} 5 | \alias{use_project_gitignore} 6 | \alias{use_project_readme} 7 | \title{Write a template file} 8 | \usage{ 9 | use_project_file( 10 | name = NULL, 11 | filename = NULL, 12 | template = NULL, 13 | open = interactive() 14 | ) 15 | 16 | use_project_gitignore(filename = NULL, template = NULL) 17 | 18 | use_project_readme(filename = NULL, template = NULL) 19 | } 20 | \arguments{ 21 | \item{name}{Name of file to write. Not sure of the files available to you? 22 | Run the function without specifying a name, and all files available within the 23 | template will print.} 24 | 25 | \item{filename}{Optional argument to specify the name of the file to be written. 26 | Paths/filename is relative to project base} 27 | 28 | \item{template}{A project template. See 29 | \href{https://www.danieldsjoberg.com/starter/articles/create_project.html}{vignette} 30 | for details.} 31 | 32 | \item{open}{If \code{TRUE}, opens the new file.} 33 | } 34 | \value{ 35 | NULL, places single template file in current working directory 36 | } 37 | \description{ 38 | Rather than using \code{create_project()} to start a new project folder, you 39 | may use \code{use_project_file()} to write a single file from any project template. 40 | The functions \code{use_project_gitignore()} and \code{use_project_readme()} are shortcuts for 41 | \code{use_project_file("gitignore")} and \code{use_project_file("readme")}. 42 | } 43 | \examples{ 44 | # only run fn interactively, will place files in current working dir 45 | if (interactive()) { 46 | # create gitignore file 47 | use_project_file("gitignore") 48 | use_project_gitignore() 49 | 50 | # create README.md file 51 | use_project_file("readme") 52 | use_project_readme() 53 | } 54 | } 55 | \seealso{ 56 | \code{\link[=create_project]{create_project()}} 57 | 58 | \href{https://www.danieldsjoberg.com/starter/articles/create_project.html}{Vignette for \code{create_project()}} 59 | } 60 | -------------------------------------------------------------------------------- /starter.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | LineEndingConversion: Posix 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | # if(requireNamespace('spelling', quietly = TRUE)) 2 | # spelling::spell_check_test(vignettes = TRUE, error = FALSE, 3 | # skip_on_cran = TRUE) 4 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(starter) 3 | 4 | test_check("starter") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-create_project.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("create_project() works", { 3 | proj_dir <- fs::path(tempdir(), "My Project Folder with symlink") 4 | data_dir <- fs::path(tempdir(), "secure_data") 5 | fs::dir_create(data_dir) 6 | expect_error( 7 | create_project( 8 | path = proj_dir, 9 | path_data = data_dir, 10 | git = TRUE, 11 | renv = FALSE, 12 | symlink = TRUE, 13 | open = FALSE # don't open project in new RStudio session 14 | ), 15 | NA 16 | ) 17 | 18 | proj_dir <- fs::path(tempdir(), "My Project Folder") 19 | expect_error( 20 | create_project( 21 | path = proj_dir, 22 | git = NA, 23 | renv = NA, 24 | symlink = NA, 25 | open = FALSE # don't open project in new RStudio session 26 | ), 27 | NA 28 | ) 29 | 30 | override_template <- project_templates[["default"]] 31 | attr(override_template, "arg_override") <- list(git = FALSE, renv = FALSE) 32 | expect_error( 33 | create_project( 34 | path = proj_dir, 35 | template = override_template, 36 | overwrite = TRUE, 37 | open = FALSE # don't open project in new RStudio session 38 | ), 39 | NA 40 | ) 41 | 42 | # save existing wd 43 | oldwd <- getwd() 44 | setwd(proj_dir) 45 | expect_error( 46 | use_project_gitignore(), 47 | NA 48 | ) 49 | expect_error( 50 | use_project_readme(), 51 | NA 52 | ) 53 | setwd(oldwd) 54 | 55 | # expecting error message 56 | expect_error( 57 | create_project( 58 | path = proj_dir, 59 | template = quote(stop()), 60 | overwrite = TRUE, 61 | git = FALSE, 62 | renv = FALSE, 63 | open = FALSE # don't open project in new RStudio session 64 | ) 65 | ) 66 | }) 67 | 68 | 69 | test_that("test checks on template structure", { 70 | expect_error( 71 | check_template_structure(letters) 72 | ) 73 | 74 | expect_error( 75 | as.list(letters) %>% 76 | setNames(letters) %>% 77 | check_template_structure() 78 | ) 79 | 80 | expect_error( 81 | list(a = list(gitignore = "test")) %>% 82 | check_template_structure() 83 | ) 84 | 85 | # don't error with 'copy' name 86 | expect_error( 87 | list(a = list(filename = "test", 88 | template_filename = .find_project_root(), 89 | copy = TRUE)) %>% 90 | check_template_structure(), 91 | NA 92 | ) 93 | 94 | # check for bad type in glue element 95 | expect_error( 96 | list(a = list(filename = "test", 97 | template_filename = "test", 98 | copy = "TRUE")) %>% 99 | check_template_structure(), 100 | ) 101 | expect_error( 102 | list(a = list(filename = "test", 103 | template_filename = "test", 104 | copy = TRUE)) %>% 105 | check_template_structure(), 106 | ) 107 | }) 108 | -------------------------------------------------------------------------------- /tests/testthat/test-create_symlink.R: -------------------------------------------------------------------------------- 1 | test_that("create_symlink() throws error when expected", { 2 | expect_error( 3 | create_symlink(to = letters, name = letters) 4 | ) 5 | expect_error( 6 | create_symlink(to = letters, name = fs::path_package("starter")) 7 | ) 8 | expect_error( 9 | create_symlink(to = letters, name = fs::path(fs::path_package("starter"), "rstudio", "addins.dcf")) 10 | ) 11 | expect_error( 12 | create_symlink(to = fs::path(fs::path_package("starter"), "rstudio", "addins.dcf")) 13 | ) 14 | }) 15 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/create_project.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Project Starter" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Project Starter} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r setup, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | library(dplyr) 16 | ``` 17 | 18 | ## Introduction 19 | 20 | This vignette will walk you through the `create_project()` function. 21 | The function creates a new directory or populates an existing project directory with essential files needed for a new analysis project. 22 | Existing files in the directory will not be overwritten, unless the user specifically requests to overwrite them. 23 | 24 | By default the directory is populated with customized `README.md`, `.gitignore`, and `.Rproj` files. 25 | Users can also create a personalized project templates. Instructions for creating your own template is detailed in the [custom templates section](#custom_template). 26 | 27 | ## Default Template 28 | 29 | Let's create a new project and inspect the results. 30 | The new project will be created in a the folder called `"My Project Folder"`. 31 | 32 | ```{r proj-setup, message=FALSE} 33 | # loading packages 34 | library(starter) 35 | 36 | # specifying project folder location (folder does not yet exist) 37 | project_path <- fs::path(tempdir(), "My Project Folder") 38 | ``` 39 | 40 | Let's set up our new project. 41 | 42 | ```{r proj-create} 43 | create_project( 44 | path = project_path, 45 | open = FALSE # don't open project in new RStudio session 46 | ) 47 | ``` 48 | 49 | The directory was created, files added, a git repository was initialised in the folder, and the reproducible environment was constructed with the renv package. 50 | 51 | ### **`README.md`** 52 | 53 | The following is the `README.md` file added the project directory. 54 | It's pre-filled with information specific to this project. 55 | The first line of the file is the project folder name, followed by a R code for creating a symbolic link from the project folder to the secure data folder. 56 | 57 | ```{r readme, comment = "", echo=FALSE} 58 | readr::read_file(fs::path(project_path, "README.md")) %>% cat() 59 | ``` 60 | 61 | ### **`.gitignore`** 62 | 63 | The `.gitignore` file is populated with various R files, data file types, and miscellaneous files typically not wanted in a Git repository. 64 | 65 | ```{r gitignore, comment = "", echo=FALSE} 66 | readr::read_file(fs::path(project_path, ".gitignore")) %>% cat() 67 | ``` 68 | 69 | ## Custom Template {#custom_template} 70 | 71 | While the default template is useful, it can of course, be useful to create a custom template for yourself or your team. 72 | To create a custom template, you'll need two things: 73 | 74 | 1. Template files 75 | 76 | 1. Meta data for each template file (e.g. location of template file, file name, etc.) 77 | 78 | ### Template Files 79 | 80 | There are two kinds of template files. 81 | The first are static files that a merely copied into the new project folder. 82 | The `.gitignore` file described above in the default template is an example of a file static file. 83 | 84 | The second type of template file contain data or information specific to the new project. 85 | In the default template described above, the `README.md` file is an example of these dynamic template files. 86 | The `README.md` file is populated with the project name, and the project-specific code for creating a symbolic link to the secure data folder. 87 | The following fields are available to include in the dynamic templates. 88 | 89 | {{folder_name}} project folder name 90 | {{folder_first_word}} first word of folder name 91 | {{symbolic_link}} code for establishing symbolic link to data folder 92 | {{foo()}} any R function, e.g. `Sys.Date()` 93 | 94 | Each of these fields are accessible via standard `glue::glue()` syntax, with the exception that double curly brackets are needed rather than single (e.g. `glue::glue(., .open = "{{", .close = "}}")`). 95 | 96 | Below is an example of the dynamic `README.md` template from the default template. 97 | 98 | ```{r, comment = "", echo=FALSE} 99 | readr::read_file(system.file("project_templates/default_readme.md", package = 'starter')) %>% cat() 100 | ``` 101 | 102 | ### Metadata 103 | 104 | In order to create a template, you must add a metadata object that stores information about each template file. 105 | The metadata is stored as a named list: one element in the list per file in the template. 106 | 107 | The list elements may be named any proper name within R. 108 | However, the names must be unique and we recommend short names. 109 | These do not need to match/reference any other text in the template file. 110 | 111 | ```{r my_template} 112 | my_template <- 113 | list( 114 | gitignore = list(), 115 | readme = list(), 116 | rproj = list() 117 | ) 118 | ``` 119 | 120 | Each element of the list is itself a list. 121 | The lists contain three important pieces of information about each template file. 122 | 123 | 1. The template path and file name. 124 | 125 | 1. The name of the file after it's been copied to the new project folder. 126 | 127 | 1. A logical argument indicating whether the file is a straight copy, or a dynamic file (described above). 128 | 129 | The metadata for the `README.md` file in the default template looks like this: 130 | 131 | ```{r lst-readme, eval=FALSE} 132 | readme <- 133 | list( 134 | template_filename = system.file("project_templates/default_readme.md", package = "starter"), 135 | filename = "README.md", 136 | glue = TRUE 137 | ) 138 | ``` 139 | 140 | Note that in this case, the location of the template file is pointing to a file location where the {starter} package is installed. 141 | If you are not saving your template in an R package, your `template_file` path will likely point to a folder in your machine, e.g. `"C:/project_templates/default_readme.md"` 142 | 143 | As another example, here's the metadata for the `*.Rproj` file from the default template. 144 | Note that the file name can be dynamic (the use of `glue::glue()`), while the underlying file is not dynamic (`glue = FALSE`). 145 | The list is stored as an expression so the template meta data is not evaluated until you call the `create_project()` function, allowing files to be dynamically named and template files to be saved within a package. 146 | 147 | ```{r rproj, eval=FALSE} 148 | rproj <- 149 | rlang::expr(list( 150 | template_filename = system.file("project_templates/default_rproj.Rproj", package = "starter"), 151 | filename = glue::glue("{folder_name}.Rproj"), 152 | glue = FALSE 153 | )) 154 | ``` 155 | 156 | Below is an example of a simple custom template. 157 | 158 | ```{r full-template} 159 | my_template <- 160 | list( 161 | readme = rlang::expr(list( 162 | template_filename = system.file("project_templates/default_readme.md", package = "starter"), 163 | filename = "README.md", 164 | glue = TRUE 165 | )), 166 | rproj = rlang::expr(list( 167 | template_filename = system.file("project_templates/default_rproj.Rproj", package = "starter"), 168 | filename = glue::glue("{folder_name}.Rproj"), 169 | glue = FALSE 170 | )), 171 | gitignore = rlang::expr(list( 172 | template_filename = system.file("project_templates/default_gitignore.txt", package = "starter"), 173 | filename = ".gitignore", 174 | glue = TRUE 175 | )) 176 | ) 177 | ``` 178 | 179 | Note that you are able to put files into subfolders by including the subfolder name in the `filename` argument. This can be done for any type of file. 180 | Here's an example of what the metadata could look like if the user has a static Rmarkdown template called `template_analysis.Rmd` that they want to copy into a project subfolder called `scripts`. 181 | 182 | ```{r analysis, eval = FALSE} 183 | analysis <- 184 | list( 185 | template_filename = "C:/project_templates/template_analysis.Rmd", 186 | filename = "scripts/analysis.Rmd", 187 | glue = FALSE 188 | ) 189 | ``` 190 | 191 | ### Advanced Features 192 | 193 | You may also `source()` an R script by adding the path to the file as a template attribute. 194 | The script will be sourced after project template has been placed. 195 | This feature is often used when you'd like to add an empty folder to your project. 196 | 197 | ```r 198 | attr(my_template, "script_path") <- "" 199 | ``` 200 | 201 | Wrap the path to the script in an expression if you need to delay the evaluation of the path string. 202 | 203 | You can also override the `create_project()` arguments by adding an attribute with a named list of the argument values you'd like the template to use. 204 | For example, if you always want to initialize the git repo and never use renv, attach this list `list(git = TRUE, renv = FALSE)` as an attribute called `"arg_override"`. 205 | 206 | There is one last step---give your template a label. 207 | The label will be displayed each time the template is called in either `create_project()` or `use_project_file()`. 208 | 209 | ```{r label} 210 | attr(my_template, "label") <- "My 1st Project Template" 211 | ``` 212 | 213 | It is recommended you create the list elements named `'readme'` and `'gitignore'`. 214 | The `'readme'` element is used in the in the `use_project_readme()` function and `'gitignore'` is in the `use_project_gitignore()` function---without these elements, these useful functions will return errors. 215 | 216 | ### Implement Custom Template 217 | 218 | Now that you have a folder with your template files stored and you have created a metadata list object, you can use them to create a new project folder with your custom template. 219 | The following code will get you started. 220 | 221 | ```{r unlink, include=FALSE, echo=FALSE} 222 | unlink(project_path, recursive = TRUE) 223 | ``` 224 | 225 | ```{r create_project} 226 | create_project( 227 | path = project_path, 228 | template = my_template # metadata list created above 229 | ) 230 | ``` 231 | --------------------------------------------------------------------------------