Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/rostools/prodigenr
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjohnst86 committed Nov 30, 2024
2 parents c794b71 + 709332c commit 8b6146b
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 132 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
^CRAN-RELEASE$
^\.github$
^CRAN-SUBMISSION$
^justfile$
14 changes: 1 addition & 13 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ These changes are for PURPOSE, because REASON.

Closes #

## Reviewer Focus

This PR needs a quick/an in-depth review.

Focus on CHANGES.

## Checklist

- [ ] Ran `devtools::document()`
- [ ] Ran `devtools::test()`
- [ ] Ran `devtools::spell_check()`
- [ ] Ran `styler::style_pkg()`
- [ ] Ran `devtools::lint()`
- [ ] Ran `devtools::build_site()`
- [ ] Ran `devtools::check()`
- [ ] Ran `just run-all`
- [ ] If docs were added, Markdown is formatted
24 changes: 24 additions & 0 deletions .github/workflows/assign-pr-to-creator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Assign PR to creator

on:
pull_request:
types:
- reopened
- opened

permissions:
pull-requests: write

jobs:
assign-pr-to-creator:
name: Assign PR to creator
runs-on: ubuntu-latest
steps:
- name: Assign PR to creator
if: ${{ github.event_name == 'pull_request' }}
run: |
gh pr edit $PR --add-assignee $AUTHOR
env:
AUTHOR: ${{ github.event.pull_request.user.login }}
PR: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters: linters_with_defaults(
line_length_linter(100),
commented_code_linter = NULL
)
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Imports:
withr,
rlang,
cli,
whisker
whisker,
gert
Suggests:
testthat,
knitr,
gert
knitr
VignetteBuilder: knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
`usethis::use_blank_slate("project")` (#144).
- New projects have Git added from the beginning, so don't need to use
`setup_with_git()` (#148).
- Move `gert` to imports, since it makes more sense that it should be
a hard dependency as the project is an opinionated project creator
(#145).

## Fixes and improvements

Expand All @@ -17,6 +20,9 @@
- The `title` field in the `DESCRIPTION` file is needed by many
usethis functions, so it is added to the created `DESCRIPTION` file
(#137).
- It isn't always useful to have the report created when the project
is setup, so adding the report via `create_report()` is removed from
`project_setup()` (#142).

# prodigenr 0.6.2

Expand Down Expand Up @@ -130,3 +136,4 @@
- Added a `NEWS.md` file to track changes to the package.
- Fixed a bug that prevented an Rproj file and the Rprofile files from
being installed and created.

7 changes: 3 additions & 4 deletions R/rstudio_setup.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

rstudio_setup <- function(path, ...) {
# create project
setup_project(path = path)
invisible(NULL)
# create project
setup_project(path = path)
invisible(NULL)
}
86 changes: 42 additions & 44 deletions R/setup_project.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,36 @@
#' setup_with_git()
#' }
setup_project <-
function(path) {
stopifnot(is.character(path))
proj_path <- fs::path_abs(path)
proj_name <- fs::path_file(proj_path)
function(path) {
stopifnot(is.character(path))
proj_path <- fs::path_abs(path)
proj_name <- fs::path_file(proj_path)

if (grepl(" ", basename(proj_path))) {
rlang::warn("Project name has a space in it, replacing with a dash (-).")
proj_path <- path_remove_spaces(proj_path)
}
if (grepl(" ", basename(proj_path))) {
rlang::warn("Project name has a space in it, replacing with a dash (-).")
proj_path <- path_remove_spaces(proj_path)
}

if (fs::dir_exists(proj_path)) {
cli::cli_abort(c("The {.val {proj_path}} folder already exists, so project creation is canceled.",
"i" = "Delete the folder or use another name (not {.val {proj_name}}) for your project."))
}
proj_template <- find_template("projects", "basic-analysis")
fs::dir_copy(proj_template, new_path = proj_path)
if (fs::dir_exists(proj_path)) {
cli::cli_abort(c(
"The {.val {proj_path}} folder already exists, so project creation is canceled.",
"i" = "Delete the folder or use another name (not {.val {proj_name}}) for your project."
))
}
proj_template <- find_template("projects", "basic-analysis")
fs::dir_copy(proj_template, new_path = proj_path)

withr::with_dir(
new = proj_path,
code = {
update_template("DESCRIPTION", data = list(ProjectName = proj_name))
update_template("template-Rproj", paste0(proj_name, ".Rproj"))
fs::file_delete("template-Rproj")
update_template("README.md", data = list(ProjectName = proj_name))
withr::with_dir(
new = proj_path,
code = {
update_template("DESCRIPTION", data = list(ProjectName = proj_name))
update_template("template-Rproj", paste0(proj_name, ".Rproj"))
fs::file_delete("template-Rproj")
update_template("README.md", data = list(ProjectName = proj_name))
gert::git_init()
}
}
)
}

# Git setup functions -------------------------------------------

Expand All @@ -53,32 +56,27 @@ setup_project <-
#' Takes a lot of inspiration from the usethis `use_git()` function, except
#' it only adds Git and nothing more (doesn't commit, doesn't restart RStudio
#' automatically). Must run this function inside the project you created from
#' [setup_project()]
#' [setup_project()].
#'
#' @return Adds Git and `.gitignore` file to the project.
#' @export
#' @seealso [setup_project()] for starting the project.
#'
setup_with_git <- function() {
if (!requireNamespace("gert", quietly = TRUE)) {
cli::cli_abort(
c("This function relies on the gert package, please install it and then run the function again.",
"i" = "Install with: {.code install.packages('gert')}")
)
}

if (!is_rproj_folder())
cli::cli_abort(c("The folder does not contain an {.val .Rproj} file.",
"i" = "Please use this function while in the project created from {.code prodigenr::setup_project().}"))
if (!is_rproj_folder()) {
cli::cli_abort(c("The folder does not contain an {.val .Rproj} file.",
"i" = "Please use this function while in the project created from {.code prodigenr::setup_project().}"
))
}

if (has_git()) {
rlang::abort("The project already has Git added.")
}
if (has_git()) {
rlang::abort("The project already has Git added.")
}

gert::git_init()
set_git_ignore_files()
cli::cli_alert_info("You'll need to restart RStudio to see the Git pane.")
return(invisible(NULL))
gert::git_init()
set_git_ignore_files()
cli::cli_alert_info("You might need to restart RStudio to see the Git pane.")
return(invisible(NULL))
}

# Utilities -----------------------------------------------------
Expand All @@ -91,8 +89,8 @@ set_git_ignore_files <- function() {
}

path_remove_spaces <- function(path) {
path_as_vector <- fs::path_split(path)[[1]]
last_dir <- length(path_as_vector)
path_as_vector[last_dir] <- gsub(" +", "-", path_as_vector[last_dir])
fs::path_join(path_as_vector)
path_as_vector <- fs::path_split(path)[[1]]
last_dir <- length(path_as_vector)
path_as_vector[last_dir] <- gsub(" +", "-", path_as_vector[last_dir])
fs::path_join(path_as_vector)
}
22 changes: 12 additions & 10 deletions R/usethis-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Expand All @@ -27,25 +27,27 @@
update_template <- function(template,
save_as = template,
data = list()) {
template_contents <-
base::strsplit(whisker::whisker.render(read_utf8(template),
data), "\n")[[1]]
new <- base::writeLines(template_contents, save_as)
invisible(new)
template_contents <-
base::strsplit(whisker::whisker.render(
read_utf8(template),
data
), "\n")[[1]]
new <- base::writeLines(template_contents, save_as)
invisible(new)
}

# Taken from usethis package and modified to this package.
find_template <- function(...) {
fs::path_package(package = "prodigenr", "templates", ...)
fs::path_package(package = "prodigenr", "templates", ...)
}

# Taken from usethis package
read_utf8 <- function(path, n = -1L) {
base::readLines(path, n = n, encoding = "UTF-8", warn = FALSE)
base::readLines(path, n = n, encoding = "UTF-8", warn = FALSE)
}

# Taken from usethis:::uses_git
has_git <- function(project_path = ".") {
repo <- tryCatch(gert::git_find(project_path), error = function(e) NULL)
!is.null(repo)
repo <- tryCatch(gert::git_find(project_path), error = function(e) NULL)
!is.null(repo)
}
7 changes: 4 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
is_rproj_folder <- function() {
rprojroot::is.root_criterion(rprojroot::is_rstudio_project)
rprojroot::is.root_criterion(rprojroot::is_rstudio_project)
}

viz_project_tree <- function(path) {
withr::with_dir(fs::path_dir(path),
{fs::dir_tree(basename(path), all = TRUE)})
withr::with_dir(fs::path_dir(path), {
fs::dir_tree(basename(path), all = TRUE)
})
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ knitr::opts_chunk$set(
)
```

# Project creation with prodigenr: A component of reproducible and open scientific projects <img src="man/figures/logo.png" style="text-align: right;"/>
# Create projects with prodigenr <img src="man/figures/logo.png" style="text-align: right;" width="70"/>

<!-- badges: start -->

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# Project creation with prodigenr: A component of reproducible and open scientific projects <img src="man/figures/logo.png" style="text-align: right;"/>
# Create projects with prodigenr <img src="man/figures/logo.png" style="text-align: right;" width="70"/>

<!-- badges: start -->

Expand Down
49 changes: 34 additions & 15 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
# These are for admin tasks that really only need to be done once or twice

@_default:
just --list --unsorted
just --list --unsorted

# Run build recipes and install the package
build: style document test install-package check
# Run all recipes
run-all: install-package-dependencies document spell-check style lint test build-site check install-package

# Install the package and its dependencies
install-package:
# Install package dependencies
install-package-dependencies:
#!/usr/bin/Rscript
devtools::install()
pak::pak(ask = FALSE)

# Run document generators
document:
#!/usr/bin/Rscript
devtools::document()

# Run tests
test:
test:
#!/usr/bin/Rscript
devtools::test()

# Re-build Roxygen docs
document:
# Check spelling
spell-check:
#!/usr/bin/Rscript
devtools::document()
devtools::spell_check()

# Run style formatter
style:
# Style all R code
style:
#!/usr/bin/Rscript
styler::style_pkg()

# Run CRAN check
# Run linter
lint:
#!/usr/bin/Rscript
devtools::lint(
)

# Build pkgdown website
build-site:
#!/usr/bin/Rscript
devtools::build_site()

# Run local CRAN checks
check:
#!/usr/bin/Rscript
devtools::check()

# Install prodigenr as a package
install-package: install-package-dependencies
#!/usr/bin/Rscript
devtools::install()
2 changes: 1 addition & 1 deletion man/setup_with_git.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion prodigenr.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ AlwaysSaveHistory: No

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 4
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: knitr
Expand All @@ -19,3 +19,9 @@ BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace,vignette

UseNativePipeOperator: Yes

MarkdownWrap: Column
MarkdownWrapAtColumn: 72
MarkdownCanonical: Yes
Loading

0 comments on commit 8b6146b

Please sign in to comment.