-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
5,224 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
add_gitignore <- function(to_add, path = ".") { | ||
|
||
gitignore_file <- file.path(path, ".gitignore") | ||
|
||
if (!file.exists(gitignore_file)) { | ||
writeLines("", gitignore_file) | ||
} | ||
|
||
git_ignore <- readLines(gitignore_file) | ||
|
||
to_ignore <- to_add[!to_add %in% git_ignore] | ||
|
||
if (length(to_ignore) != 0) { | ||
writeLines(enc2utf8(c(git_ignore, to_ignore)), gitignore_file) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
add_rbuildignore <- function(to_add, path = ".") { | ||
|
||
build_file <- file.path(path, ".Rbuildignore") | ||
|
||
if (!file.exists(build_file)) { | ||
writeLines("", build_file) | ||
} | ||
|
||
build_ignore <- readLines(build_file) | ||
|
||
to_ignore <- paste0("^", gsub("[.]", "\\\\.", to_add), "$") | ||
|
||
to_ignore <- to_ignore[!to_ignore %in% build_ignore] | ||
|
||
if (length(to_ignore) != 0) { | ||
writeLines(enc2utf8(c(build_ignore, to_ignore)), build_file) | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
convert_df_to_md <- function(df, center_cols = TRUE, ...) { | ||
|
||
cols <- as.character(names(df)) | ||
|
||
headr <- paste0( | ||
c( | ||
"|", | ||
purrr::map_chr(cols, create_md_head) | ||
), | ||
collapse = "" | ||
) | ||
|
||
sepr <- paste0( | ||
c( | ||
"|", | ||
purrr::map_chr(cols, create_md_sep, align = "center") | ||
), | ||
collapse = "" | ||
) | ||
|
||
top <- paste0(c(headr, sepr), collapse = "\n") | ||
|
||
st <- "|" | ||
for (i in 1:nrow(df)) { | ||
for (j in 1:ncol(df)) { | ||
if (j %% ncol(df) == 0) { | ||
st <- paste0( | ||
st, | ||
as.character(df[i, j]), | ||
"|", | ||
"\n", | ||
"", | ||
"|", | ||
collapse = "" | ||
) | ||
} else { | ||
st <- paste0(st, as.character(df[i, j]), "|", collapse = "") | ||
} | ||
} | ||
} | ||
|
||
fin <- paste0(c(headr, sepr, substr(st, 1, nchar(st) - 1)), collapse = "\n") | ||
|
||
cat(fin) | ||
|
||
} | ||
|
||
|
||
|
||
create_md_head <- function(word, ...) { | ||
|
||
len <- nchar(word) | ||
if (len <= 3) { | ||
pref <- " " | ||
suff <- " " | ||
} else { | ||
pref <- " " | ||
suff <- " " | ||
} | ||
|
||
out <- paste0(pref, word, suff, collapse = "") | ||
|
||
if (nchar(out) < 7) { | ||
out <- paste0(out, rep(" ", (7 - nchar(out))), collapse = "") | ||
} | ||
|
||
out <- paste0(out, "|") | ||
|
||
return(out) | ||
|
||
} | ||
|
||
create_md_sep <- function(word, align = c("left", "right", "center")) { | ||
|
||
align <- match.arg(align) | ||
|
||
len <- nchar(word) | ||
len_dash <- max(3, len - 2) | ||
|
||
if (align == "center") { | ||
out <- paste0( | ||
":", | ||
paste0(rep("-", len_dash), collapse = ""), | ||
":", | ||
collapse = "" | ||
) | ||
} else if (align == "right") { | ||
out <- paste0( | ||
paste0(rep("-", len_dash), collapse = ""), | ||
":", | ||
collapse = "" | ||
) | ||
} else { | ||
out <- paste0(rep("-", len_dash), collapse = "") | ||
} | ||
|
||
out <- paste0(" ", out, " |") | ||
|
||
return(out) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,67 @@ | ||
#' Create R Package | ||
#' | ||
#' @description | ||
#' This function is a wrapper around [usethis::create_package()] with some | ||
#' added functionality listed in details below. | ||
#' | ||
#' @param path Path to create package | ||
#' @param pkgdevt_script Boolean - Should a `pkgdevt.R` script be created? | ||
#' @param open Should the new package be opened? | ||
#' @param ... Passed onto [usethis::create_package()] | ||
#' | ||
#' @return invisibly returns 0; used for side-effects. | ||
#' @export | ||
#' | ||
#' @importFrom rstudioapi openProject | ||
#' @importFrom usethis create_package with_project | ||
create_pkg <- function(path, pkgdevt_script = TRUE, open = TRUE, ...) { | ||
|
||
usethis::create_package(path = path, open = FALSE, ...) | ||
if (pkgdevt_script) usethis::with_project(path = path, use_pkgdevt_script(open = FALSE)) | ||
if (open) rstudioapi::openProject(path = path) | ||
invisible(0) | ||
|
||
} | ||
#' #' Create R Package | ||
#' #' | ||
#' #' @description | ||
#' #' This function is a wrapper around [usethis::create_package()] with some | ||
#' #' added functionality listed in details below. | ||
#' #' | ||
#' #' @param path Path to create package | ||
#' #' @param pkgdevt_script Boolean - Should a `pkgdevt.R` script be created? | ||
#' #' @param open Should the new package be opened? | ||
#' #' @param ... Passed onto [usethis::create_package()] | ||
#' #' | ||
#' #' @return invisibly returns 0; used for side-effects. | ||
#' #' @export | ||
#' #' | ||
#' #' @importFrom rstudioapi openProject | ||
#' #' @importFrom usethis create_package with_project | ||
#' create_pkg <- function(path, pkgdevt_script = TRUE, open = TRUE, ...) { | ||
#' | ||
#' usethis::create_package(path = path, open = FALSE, ...) | ||
#' if (pkgdevt_script) usethis::with_project(path = path, use_pkgdevt_script(open = FALSE)) | ||
#' if (open) rstudioapi::openProject(path = path) | ||
#' invisible(0) | ||
#' | ||
#' } | ||
#' | ||
#' | ||
#' new_pkg <- function( | ||
#' name, | ||
#' path = getwd(), | ||
#' description = getOption("pkgdev.description", default = getOption("usethis.description", default = NULL)), | ||
#' name_check = TRUE, | ||
#' rstudio = TRUE, | ||
#' roxygen = TRUE, | ||
#' testthat = TRUE, | ||
#' pkgdown = TRUE, | ||
#' changelog = TRUE, | ||
#' git = TRUE, | ||
#' github= TRUE, | ||
#' github_actions = c(), | ||
#' github_labels = c(), | ||
#' dependabot = TRUE, | ||
#' stale = TRUE, | ||
#' gitignore = TRUE, | ||
#' gitattributes = TRUE, | ||
#' devcontainer = TRUE, | ||
#' docker = TRUE, | ||
#' attachment = TRUE, | ||
#' papillon = TRUE, | ||
#' ... | ||
#' ) { | ||
#' | ||
#' # setup logging | ||
#' log_lvl <- Sys.getenv("LOG_LEVEL", unset = "INFO") | ||
#' | ||
#' | ||
#' } | ||
#' | ||
#' | ||
#' | ||
#' opts = list( | ||
#' "dev_dir" = TRUE, | ||
#' "pkgdevt_script" = TRUE, | ||
#' | ||
#' ) | ||
#' | ||
#' | ||
#' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#' Logging Functions | ||
#' | ||
#' @description | ||
#' Suite of logging functions for use in the `pkgdev` R package. | ||
#' | ||
#' @include utils.R options.R | ||
NULL | ||
|
||
log_config.verbosity <- local({ | ||
.val <- | ||
}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
## usethis namespace: end | ||
NULL | ||
|
||
#' @eval options::as_roxygen_docs() | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# use_readme_md_template <- function(...) { | ||
# | ||
# | ||
# | ||
# } | ||
# | ||
# md_icon_warning <- function(...) { | ||
# paste0( | ||
# ":warning: ", | ||
# ..., | ||
# collapse = "" | ||
# ) | ||
# } | ||
# | ||
# md_icon_info <- function(...) { | ||
# paste0( | ||
# ":information_source: ", | ||
# ..., | ||
# collapse = "" | ||
# ) | ||
# } | ||
# | ||
# md_icon_ |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# R Database Connection Helper Functions | ||
|
||
> Description | ||
## Contents | ||
|
||
[TOC] | ||
|
||
## Overview | ||
|
||
|
||
|
||
## Pool | ||
|
||
### `pool_connect` | ||
|
||
```r | ||
pool_connect <- function(..., config = NULL, schema = NULL) { | ||
if (is.null(config)) { | ||
stopifnot( | ||
'dbname' %in% names(config), | ||
'host' %in% names(config), | ||
'port' %in% names(config), | ||
'user' %in% names(config), | ||
'password' %in% names(config) | ||
) | ||
} else { | ||
config <- config::get("db") | ||
} | ||
|
||
opts <- schema | ||
if (!is.null(opts)) opts <- paste0("-c search_path=", schema) | ||
|
||
conn <- pool::dbPool( | ||
RPostgres::Postgres(), | ||
dbname = config$dbname, | ||
host = config$host, | ||
port = config$port, | ||
user = config$user, | ||
password = config$password, | ||
options = opts | ||
) | ||
|
||
if (!pool::dbIsValid(conn)) stop("Connection is not valid, please try again.") | ||
|
||
options(pool.conn = conn) | ||
|
||
conn | ||
} | ||
``` | ||
|
||
### `get_pool()` | ||
|
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# GitHub Actions for R Package Developers | ||
|
||
> List of various, useful GitHub Action Workflows for R Package Development. | ||
|
||
|
||
## Contents | ||
|
||
[TOC] | ||
|
||
## Overview | ||
|
||
|
||
|
||
## Workflows | ||
|
||
- [R CMD CHECK (`rcmdcheck.yml`)]() | ||
- [`rcmdcheck-full.yml`]() | ||
- [`rcmdcheck-standard.yml`]() | ||
- |
Empty file.
Oops, something went wrong.