Skip to content

Commit

Permalink
Merge pull request #40 from RaymondBalise/add_analysis_with_examples
Browse files Browse the repository at this point in the history
Add analysis with examples
  • Loading branch information
RaymondBalise authored Feb 15, 2024
2 parents 26203d5 + 897f9ab commit b0e7cf8
Show file tree
Hide file tree
Showing 10 changed files with 560 additions and 18 deletions.
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rUM
Title: R Templates from the University of Miami
Version: 1.0.2
Version: 1.1.0
Authors@R:
c(
person(
Expand Down Expand Up @@ -46,20 +46,23 @@ Depends:
Imports:
bookdown,
conflicted,
glue,
gtsummary,
rio,
rlang,
rmarkdown,
table1,
tidymodels,
tidyverse,
usethis
Suggests:
knitr,
tidymodels,
tinytex
License: MIT + file LICENSE
URL:
https://raymondbalise.github.io/rUM/,
https://github.com/RaymondBalise/rUM
BugReports: https://github.com/RaymondBalise/rUM/issues
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
export(make_project)
importFrom(bookdown,html_document2)
importFrom(conflicted,conflict_prefer)
importFrom(glue,glue)
importFrom(gtsummary,tbl_summary)
importFrom(rio,import)
importFrom(rlang,abort)
importFrom(rmarkdown,html_document)
importFrom(table1,t1kable)
importFrom(tidymodels,tidymodels_prefer)
importFrom(tidyverse,tidyverse_logo)
importFrom(usethis,create_project)
importFrom(utils,download.file)
52 changes: 43 additions & 9 deletions R/make_project.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' \code{./rstudio/templates/project/})
#' @param type Choose between "Quarto (analysis.qmd)" or
#' "R Markdown (analysis.Rmd)"
#' @param example Will the analysis file include an example table/figure?"
#'
#' @details Behind the scenes, this function used by research_project.dcf when
#' a user selects New project... > New Directory > rUM Research Project Template
Expand All @@ -25,6 +26,10 @@
#' @importFrom rlang abort
#' @importFrom utils download.file
#' @importFrom usethis create_project
#' @importFrom glue glue
#' @importFrom gtsummary tbl_summary
#' @importFrom rio import
#' @importFrom tidymodels tidymodels_prefer
#'
#' @return Returns nothing. See description above.
#'
Expand All @@ -40,7 +45,8 @@

make_project <- function(
path,
type = c("Quarto (analysis.qmd)", "R Markdown (analysis.Rmd)")
type = c("Quarto (analysis.qmd)", "R Markdown (analysis.Rmd)"),
example = FALSE
) {

type <- match.arg(type)
Expand All @@ -65,6 +71,19 @@ make_project <- function(
"ee3369492aafd001b59d4390177e8b44cd0ea088/analysis.qmd"
)

gist_w_ex_path_rmd <- paste0(
"https://gist.githubusercontent.com/RaymondBalise/",
"c8399e7b3474a6022eeae373d059a042/",
"raw/094e854be27554e4e296c48e4323c4f0d1b5ba9c/analysis_with_example.Rmd"
)

gist_w_ex_path_qmd <- paste0(
"https://gist.githubusercontent.com/RaymondBalise/",
"40e8e1cc0dec94b225b7cb307f4fa959/raw/",
"f365198b41abe5b35ec7d7501d6f286f668a14d7/analysis_with_example.qmd"
)


# Prevent user from overwriting an analysis file
if (file.exists(paste0(path, "/analysis.Rmd")) ||
file.exists(paste0(path, "/analysis.qmd"))
Expand All @@ -74,15 +93,30 @@ make_project <- function(
)
}

if (type == "R Markdown (analysis.Rmd)") {
download.file(gist_path_rmd, paste0(path, "/analysis.Rmd"))
} else if (type == "Quarto (analysis.qmd)") {
download.file(gist_path_qmd, paste0(path, "/analysis.qmd"))
} else {
abort(
"The type must be 'R Markdown (analysis.Rmd)' or 'Quarto (analysis.qmd)'"
)

if (example == FALSE){ # use old templates w/o an example
if (type == "R Markdown (analysis.Rmd)") {
download.file(gist_path_rmd, paste0(path, "/analysis.Rmd"))
} else if (type == "Quarto (analysis.qmd)") {
download.file(gist_path_qmd, paste0(path, "/analysis.qmd"))
} else {
abort(
"The type must be 'R Markdown (analysis.Rmd)' or 'Quarto (analysis.qmd)'"
)
}
} else { # use newer templates w an example
if (type == "R Markdown (analysis.Rmd)") {
download.file(gist_w_ex_path_rmd, paste0(path, "/analysis.Rmd"))
} else if (type == "Quarto (analysis.qmd)") {
download.file(gist_w_ex_path_qmd, paste0(path, "/analysis.qmd"))
} else {
abort(
"The type must be 'R Markdown (analysis.Rmd)' or 'Quarto (analysis.qmd)'"
)
}
}



dir.create(paste0(path, "/data"), recursive = TRUE, showWarnings = FALSE)

Expand Down
8 changes: 5 additions & 3 deletions inst/gists/analysis_1_0_2_9001.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ date: "`r Sys.Date()`"
output:
bookdown::html_document2:
number_sections: false
bibliography: [references.bib, packages.bib]
csl: the-new-england-journal-of-medicine.csl
---

```{r setup, echo=FALSE}
Expand Down Expand Up @@ -34,9 +36,9 @@ options(dplyr.summarise.inform = FALSE)

```{r other-packages}
library(glue) # for glue()
library(rUM) # needed for the bibliography
library(rUM) # needed for the bibliography to include the package
library(rio) # for import()
# library(table1) # for table1()
library(table1) # for table1() if you want to use it instead of gtsummary
# gtsummary for tbl_summary(), add_n(), add_p(), modify_header(), bold_labels()
suppressPackageStartupMessages(library(gtsummary))
Expand All @@ -58,7 +60,7 @@ analysis <- mtcars |>
# Introduction

# Methods
Analyses were conducted with `r stringr::word(R.Version()$version.string, 1, 3)` with the `tidyverse` (`r packageVersion("tidyverse")`), `rUM` (`r packageVersion("rUM")`), `table1` (`r packageVersion("table1")`) packages used to preprocess and summarize data.[@R-base; @R-tidyverse; @tidyverse2019; @R-rUM; @R-table1]
Analyses were conducted with `r stringr::word(R.Version()$version.string, 1, 3)` with the `tidyverse` (`r packageVersion("tidyverse")`), `rUM` (`r packageVersion("rUM")`), `gtsummary` (`r packageVersion("gtsummary")`) packages used to preprocess and summarize data. [@R-base; @R-tidyverse; @tidyverse2019; @R-rUM; @R-gtsummary]

# Results

Expand Down
6 changes: 4 additions & 2 deletions inst/gists/analysis_1_0_2_9001.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ knitr:
R.options:
digits: 3 # round to three digits
editor: visual
bibliography: [references.bib, packages.bib]
csl: the-new-england-journal-of-medicine.csl
---

```{r tidyverse-tidymodels, echo=FALSE}
Expand All @@ -32,7 +34,7 @@ options(dplyr.summarise.inform = FALSE)
library(glue) # for glue()
library(rUM) # needed for the bibliography
library(rio) # for import()
# library(table1) # for table1()
library(table1) # for table1()
# gtsummary for tbl_summary(), add_n(), add_p(), modify_header(), bold_labels()
suppressPackageStartupMessages(library(gtsummary))
Expand All @@ -55,7 +57,7 @@ analysis <- mtcars |>

# Methods

Analyses were conducted with `r stringr::word(R.Version()$version.string, 1, 3)` with the `tidyverse` (`r packageVersion("tidyverse")`), `rUM` (`r packageVersion("rUM")`), `table1` (`r packageVersion("table1")`) packages used to preprocess and summarize data.[@R-base; @R-tidyverse; @tidyverse2019; @R-rUM; @R-table1]
Analyses were conducted with `r stringr::word(R.Version()$version.string, 1, 3)` with the `tidyverse` (`r packageVersion("tidyverse")`), `rUM` (`r packageVersion("rUM")`), `gtsummary` (`r packageVersion("gtsummary")`) packages used to preprocess and summarize data. [@R-base; @R-tidyverse; @tidyverse2019; @R-rUM; @R-gtsummary]

# Results

Expand Down
Loading

0 comments on commit b0e7cf8

Please sign in to comment.