Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[WIP] Certificates for Pathways to Open Science #147

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3cfc69d
Add NMFS certificate template
ateucher Dec 10, 2024
4b75f64
Convert standard certificate to qmd
ateucher Dec 10, 2024
4135f9c
nmfs-openscapes logo
ateucher Dec 10, 2024
54ba380
Update create_certificate for quarto
ateucher Dec 10, 2024
f561f77
Document; add .quarto/ dir to gitignore
ateucher Dec 10, 2024
89286c9
Add a test
ateucher Dec 10, 2024
15d2fc1
Remove nmfs prefix from output filename
ateucher Dec 10, 2024
d597b92
Fix url formatting
ateucher Dec 10, 2024
06697ec
Pass cohort_type to create_certificate(); format dates
ateucher Dec 10, 2024
cdff2e4
Use .env pronoun
ateucher Dec 10, 2024
976c779
Add NMFS certificate to vignette
ateucher Dec 10, 2024
4f0faeb
Don't use .env
ateucher Dec 10, 2024
5f5e909
Wrap certificate creation in tryCatch
ateucher Dec 10, 2024
e829de6
Inclued error message in alert from tryCatch
ateucher Dec 10, 2024
f554787
format cohort name
ateucher Dec 10, 2024
60baede
Missing comma in example
ateucher Dec 10, 2024
e71eaa1
Make sure format.Date works on Dates
ateucher Dec 10, 2024
ec6c043
tests for create_batch_certificates()
ateucher Dec 10, 2024
55f3a46
use dplyr::tibble since dplyr is in Imports
ateucher Dec 10, 2024
d74e48a
Do date formatting in create_certificate()
ateucher Dec 10, 2024
9768b7a
Dates in ISO 8061
ateucher Dec 10, 2024
0a234cb
Add pathways template
ateucher Dec 10, 2024
60aedd2
modifty create_certificate() for pathways
ateucher Dec 10, 2024
db5568e
Date in correct format in vignette
ateucher Dec 10, 2024
0f02cff
rename nmfs certificate template qmd
ateucher Dec 10, 2024
0d7af2e
Improve create_certificates() documentation
ateucher Dec 10, 2024
57b9b80
More documentation
ateucher Dec 10, 2024
77a2a17
test create_batch_certificates for failure
ateucher Dec 10, 2024
332c98c
Merge branch 'nmfs-certificates' into pathways-certificates
ateucher Dec 10, 2024
c98dff5
rename pathways certificate template
ateucher Dec 10, 2024
5070306
Add logos to Pathways certificate; match style of others
ateucher Dec 10, 2024
576abb6
Update snapshots
ateucher Dec 10, 2024
d785624
Update template names; document
ateucher Dec 10, 2024
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
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Imports:
magrittr,
parsermd,
purrr,
quarto,
rmarkdown,
rstudioapi,
stringr
Expand Down
206 changes: 136 additions & 70 deletions R/create_certificate.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,102 @@
#' @param cohort_name The name of the cohort
#' @param first_name First name of participant
#' @param last_name Last name of participant
#' @param start_date cohort start date
#' @param end_date cohort end date
#' @param start_date cohort start date. `Date` or character in a standard format
#' (eg., YYYY-MM-DD)
#' @param end_date cohort end date. `Date` or character in a standard format
#' (eg., YYYY-MM-DD)
#' @param cohort_website cohort website
#' @param cohort_type What kind of cohort are the certificates for? This will
#' choose the appropriate certificate template: `"standard"` (default) or
#' `"nmfs"`.
#' @param output_dir output directory for certificates. Default `"."`
#' @param quiet Suppress quarto warnings and other messages. Default `TRUE`.
#' Set to `FALSE` to help debug if any errors occur.
#' @param ... Other parameters passed on to [quarto::quarto_render()]
#'
#' @return Saves the file to your current working directory, and
#' returns the path to the file
#' @return Saves the file to the specified directory, and returns the path to
#' the file
#' @export
#'
#' @examples
#' \dontrun{
#' create_certificate(cohort_name = "2023-fred-hutch",
#' participant_name = "Name",
#' start_date = "Sep 19",
#' end_date = "Oct 19",
#' cohort_website = "https://openscapes.github.io/2023-fred-hutch/")
#' create_certificate(
#' cohort_name = "2023-fred-hutch",
#' first_name = "FirstName",
#' last_name = "LastName",
#' start_date = "2023-09-19",
#' end_date = "2023-10-19",
#' cohort_website = "https://openscapes.github.io/2023-fred-hutch/",
#' cohort_type = "standard"
#' )
#' }
create_certificate <- function(cohort_name,
first_name,
last_name,
start_date,
end_date,
cohort_website,
output_dir = ".") {
create_certificate <- function(
cohort_name = NULL,
first_name = NULL,
last_name = NULL,
start_date = NULL,
end_date = NULL,
cohort_website = NULL,
cohort_type = c("standard", "nmfs", "pathways"),
output_dir = ".",
quiet = TRUE,
...
) {
# adapted from https://bookdown.org/yihui/rmarkdown/params-knit.html

cohort_type <- match.arg(cohort_type)

start_date <- as.Date(start_date)
end_date <- as.Date(end_date)

template <- switch (cohort_type,
standard = system.file("certificate/certificate.qmd", package = "kyber"),
nmfs = system.file("certificate/certificate-nmfs.qmd", package = "kyber"),
pathways = system.file("certificate/certificate-pathways.qmd", package = "kyber")
)

participant_name <- paste(first_name, last_name)
rmarkdown::render(
system.file("certificate/certificate.Rmd",package = "kyber"),
params = list(
cohort_name = cohort_name,

outfile <- paste0(
ifelse(
cohort_type == "pathways",
paste0("Certificate_Pathways-to-Open-Science-", lubridate::year(start_date)),
"OpenscapesCertificate"
),
"_",
gsub("\\s+", "-", cohort_name),
"_",
gsub("\\s+", "-", participant_name),
".pdf"
)

cohort_name_formatted <- cohort_name |>
stringr::str_replace_all("[-_]+", " ") |>
stringr::str_to_title() |>
stringr::str_replace("[Nn][mM][fF][sS]", "NMFS")

quarto::quarto_render(
template,
output_format = "typst",
execute_params = list(
cohort_name = cohort_name_formatted,
participant_name = participant_name,
start_date = start_date,
end_date = end_date,
start_date = format(start_date, "%B %d, %Y"),
end_date = format(end_date, "%B %d, %Y"),
cohort_website = cohort_website
),
output_format = "pdf_document",
output_file = paste0(
"OpenscapesCertificate",
"_",
gsub("\\s+", "-", cohort_name),
"_",
gsub("\\s+", "-", participant_name),
".pdf"
),
output_dir = output_dir
output_file = outfile,
quiet = quiet,
...
)

if (output_dir != ".") {
fs::dir_create(output_dir)
fs::file_move(outfile, output_dir)
}

cli::cli_inform(
c("v" = "File written to {.path {fs::path(output_dir, outfile)}}")
)
}

Expand Down Expand Up @@ -81,46 +131,62 @@ create_certificate <- function(cohort_name,
#' )
#' }
create_batch_certificates <- function(registry,
participants,
cohort_name,
output_dir = ".") {

if (!cohort_name %in% registry$cohort_name) {
stop("'cohort_name' is not a cohort in 'registry_sheet'", call. = FALSE)
}

if (!cohort_name %in% participants$cohort) {
stop("'cohort_name' is not a cohort in 'participant_sheet'", call. = FALSE)
}

registry_cohort <- dplyr::filter(
registry,
.data$cohort_name == !!cohort_name
)

participants_cohort <- dplyr::filter(
participants,
.data$cohort == !!cohort_name
)

## Loop through each participant in list and create certificate for each

dir.create(output_dir, showWarnings = FALSE, recursive = TRUE)

for (row in seq_len(nrow(participants_cohort))) {
create_certificate(
cohort_name = registry_cohort$cohort_name,
first_name = participants_cohort$first[row],
last_name = participants_cohort$last[row],
start_date = registry_cohort$date_start,
end_date = registry_cohort$date_end,
cohort_website = registry_cohort$cohort_website,
output_dir = output_dir
participants,
cohort_name,
cohort_type,
output_dir = ".") {

if (!cohort_name %in% registry$cohort_name) {
stop("'cohort_name' is not a cohort in 'registry_sheet'", call. = FALSE)
}

if (!cohort_name %in% participants$cohort) {
stop("'cohort_name' is not a cohort in 'participant_sheet'", call. = FALSE)
}

registry_cohort <- dplyr::filter(
registry,
.data$cohort_name == !!cohort_name
)

output_dir
}

participants_cohort <- dplyr::filter(
participants,
.data$cohort == !!cohort_name
)

## Loop through each participant in list and create certificate for each

dir.create(output_dir, showWarnings = FALSE, recursive = TRUE)

for (row in seq_len(nrow(participants_cohort))) {
tryCatch({
first_name <- participants_cohort$first[row]
last_name <- participants_cohort$last[row]

create_certificate(
cohort_name = cohort_name,
first_name = first_name,
last_name = last_name,
start_date = registry_cohort$date_start,
end_date = registry_cohort$date_end,
cohort_website = registry_cohort$cohort_website,
cohort_type = cohort_type,
output_dir = output_dir
)
},
error = function(e) {
cli::cli_inform(
c(
"x" = "Unable to create certificate for {.val {paste(first_name, last_name)}}",
"i" = paste(" Error:", e$message)
)
)
}
)
}

output_dir

}


Expand Down
1 change: 1 addition & 0 deletions inst/certificate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.quarto/
35 changes: 35 additions & 0 deletions inst/certificate/certificate-nmfs.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
format: typst
params:
cohort_name: "NMFS Openscapes Champions Program"
participant_name: "Name"
start_date: "October 8"
end_date: "December 4"
cohort_website: "https://nmfs-openscapes.github.io/2024-nmfs-champions/"
files: ["nmfs-openscapes-logo.png"]
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{=typst}
#set page(numbering: none)
```

```{=typst}
#align(center, text(17pt)[
*NMFS Openscapes Champions Program \ Certificate of Completion*
])
```

Certificate of Completion: `r params$cohort_name` Cohort
`r paste0("<", params$cohort_website, ">")`

Dates: `r params$start_date` to `r params$end_date`

This certifies that `r params$participant_name` has completed the NMFS Openscapes Champions Program, a training and mentorship program in open science tools and practices for NOAA’s National Marine Fisheries Service science teams and staff. It is a multi-month program that is designed to ignite incremental and sustainable change within research teams and beyond. It helps teams get their own work done and participate in open science, while building skills and community within the realities of their busy schedules, varying expertise and needs. This was supported as part of NOAA Fisheries' data, infrastructure and workflow modernization effort. Learn more at [nmfs-openscapes.github.io/champions](https://nmfs-openscapes.github.io/champions).

<https://doi.org/10.5281/zenodo.7407246>

![](nmfs-openscapes-logo.png){width=250 fig-align="center"}
38 changes: 38 additions & 0 deletions inst/certificate/certificate-pathways.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
format: typst
params:
participant_name: "Ileana Fenwick"
start_date: "January 25"
end_date: "February 29, 2024"
cohort_name: "Pathways to Open Science"
cohort_website: "https://openscapes.github.io/pathways-to-open-science/"
---

<!--
Note: cohort_name and cohort_website are not currently used in the
certificate, but are included for compatibility with the `create_certificate()`
funtion
-->

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{=typst}
#set page(numbering: none)
```

```{=typst}
#align(center, text(17pt)[
*Openscapes Pathways to Open Science Program \
Certificate of Completion*
])
```

Dates: `r params$start_date` to `r params$end_date`

This certifies that `r params$participant_name` participated in the Pathways to Open Science program from Openscapes. Pathways to Open Science is a remote event series for Black environmental & marine researchers to build community for the future of data intensive science. Through a series of community calls and coworking sessions, participants gained practical data science skills and developed a mindset for Open Data Science: the tools and practices enabling reproducible, transparent, and inclusive practices for data intensive science. Learn more at <https://openscapes.github.io/pathways-to-open-science/>.

<https://doi.org/10.5281/zenodo.7662699>

![](logos-openscapes-bweems-bims.png){width=400 fig-align="center"}
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
---
format: typst
params:
cohort_name: "2023 Fred Hutch"
participant_name: "Lastname"
start_date: "August 29"
end_date: "October 24"
cohort_website: "https://openscapes.github.io/2023-fred-hutch/"
files: ["openscapes_hex.png"]

output: html_document
# output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{=typst}
#set page(numbering: none)
```

```{=typst}
#align(center, text(17pt)[
*Openscapes Champions Program \ Certificate of Completion*
])
```

## Openscapes Champions Program Certificate of Completion
Certificate of Completion: `r params$cohort_name` Cohort
`r params$cohort_website`
`r paste0("<", params$cohort_website, ">")`

Dates: `r params$start_date` to `r params$end_date`

Expand All @@ -27,6 +33,4 @@ This certifies that `r params$participant_name` <!---`r params$participant_name_

<https://doi.org/10.5281/zenodo.7407247>

<img src="openscapes_hex.png" width="100">


![](openscapes_hex.png){width=100 fig-align="center"}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/certificate/nmfs-openscapes-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions man/create_batch_certificates.Rd

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

Loading
Loading