Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Imports:
quarto,
rmarkdown,
rstudioapi,
stringr
stringr,
whisker
Suggests:
testthat (>= 3.0.0),
tibble,
Expand Down
12 changes: 9 additions & 3 deletions R/create_readme.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Create a README.Rmd from a Kyber Template
#'
#' @inheritParams rmarkdown::draft
#'
#' @param cohort_name The name of the cohort. Defaults to the current working directory name.
#' @importFrom rmarkdown draft
#' @importFrom rstudioapi hasFun navigateToFile
#' @export
Expand All @@ -13,14 +13,20 @@
#' kyber::create_readme()
#' }
create_readme <- function(file = "README.Rmd",
template = "openscapes-cohort-readme", edit = TRUE){
template = "openscapes-cohort-readme",
cohort_name = basename(getwd()),
edit = TRUE) {
readme <- rmarkdown::draft(
file,
template,
"kyber",
create_dir = FALSE,
edit = FALSE
)

readme_text <- readLines(readme)
readme_text <- whisker::whisker.render(readme_text, list(cohort_name = cohort_name))
writeLines(readme_text, readme)

file.copy(system.file("agendas", "horst-champions-trailhead.png", package = "kyber"),
dirname(file))
Expand All @@ -33,4 +39,4 @@ create_readme <- function(file = "README.Rmd",
}

invisible(readme)
}
}
3 changes: 2 additions & 1 deletion R/init_repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ init_repo <- function(name, org = "openscapes", path = getwd(),
create_readme(
fs::path(repo_path, "README.Rmd"),
template,
cohort_name = name,
edit = edit
)
}

invisible(repo_path)
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ library(fs)
repo_name <- "2021-ilm-rotj"

# This will open a README.Rmd for you to edit
# In yaml of README.Rmd, `cohort_name: "Cohort"` replace "Cohort" with specific cohort name
# In yaml of README.Rmd, `cohort_name:` will be automatically filled in based on `repo_name`.
# Default organization for repo is openscapes. To initialize the repo in another org,
# specify org name as in `init_repo("repo_name", org = "nmfs-openscapes")`
repo_path <- init_repo(repo_name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
params:
cohort_name: "Cohort"
cohort_name: "{{cohort_name}}"
cohort_registry: "https://docs.google.com/spreadsheets/d/1Ys9KiTXXmZ_laBoCV2QWEm7AcnGSVQaXvm2xpi4XTSc/"
output: github_document
---
Expand Down Expand Up @@ -71,4 +71,3 @@ Andy Teucher (@teucher), Openscapes
- [**Our path to better science in less time using open data science tools**](https://www.nature.com/articles/s41559-017-0160) (Lowndes et al. 2017) - This describes a marine science team’s transition to open collaborative teamwork. It was the original inspiration for creating the Champions Program and heavily influences the Core Lessons. We’ll ask that everyone participating reads it before our first Cohort Call.
- [**Supercharge your research: a ten-week plan for open data science**](https://openscapes.github.io/supercharge-research/) (Lowndes et al. 2019) - This was co-authored with the inaugural Champions Cohort, capturing the most valuable take-aways for marine and environmental science early career faculty.
- [**Shifting institutional culture to develop climate solutions with Open Science**](https://onlinelibrary.wiley.com/doi/10.1002/ece3.11341) (Lowndes et al. 2024) - This was co-authored by Openscapes mentors across organizations – including NASA Earthdata, NOAA Fisheries, EPA, California Water Boards, Pathways to Open Science, Fred Hutch Cancer Center.

3 changes: 3 additions & 0 deletions man/create_readme.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/create_readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Templates can be created.

Code
readLines(test_readme, n = 3)
Output
[1] "---" "params:"
[3] " cohort_name: \"test-cohort\""

14 changes: 8 additions & 6 deletions tests/testthat/test-create_readme.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
test_template <- function(template){
test_template <- function(template, cohort_name = "test-cohort") {
temp_file <- tempfile()

test_file_path <- kyber::create_readme(temp_file, template, edit = FALSE)
file.exists(test_file_path)
kyber::create_readme(temp_file, template, cohort_name = cohort_name, edit = FALSE)
}

test_that("Templates can be created.", {
expect_true(test_template("openscapes-cohort-readme"))
})
test_that("Templates can be created and cohort name populated", {
test_readme <- test_template("openscapes-cohort-readme")
expect_true(file.exists(test_readme))

expect_snapshot(readLines(test_readme, n = 3))
})
Loading