Skip to content

Commit

Permalink
Merge pull request #2 from jimbrig/develop
Browse files Browse the repository at this point in the history
Develop -> Main
  • Loading branch information
jimbrig authored Jan 29, 2024
2 parents 95380b0 + 056822b commit dd63f6c
Show file tree
Hide file tree
Showing 68 changed files with 5,520 additions and 53 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(check_package_name)
export(create_pkg)
export(indent)
export(inform)
export(library_dev_packages)
Expand All @@ -28,8 +27,6 @@ importFrom(glue,glue_collapse)
importFrom(here,here)
importFrom(purrr,walk)
importFrom(rlang,inform)
importFrom(rstudioapi,openProject)
importFrom(usethis,create_package)
importFrom(usethis,with_project)
importFrom(usethis,write_over)
importFrom(utils,browseURL)
Expand Down
Empty file added R/add_devcontainer.R
Empty file.
Empty file added R/add_docker.R
Empty file.
Empty file added R/add_dockerignore.R
Empty file.
Empty file added R/add_editorconfig.R
Empty file.
Empty file added R/add_gitattributes.R
Empty file.
Empty file added R/add_github.R
Empty file.
17 changes: 17 additions & 0 deletions R/add_gitignore.R
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)
}

}
19 changes: 19 additions & 0 deletions R/add_rbuildignore.R
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 added R/add_vscode.R
Empty file.
101 changes: 101 additions & 0 deletions R/convert_df_to_md.R
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)

}
91 changes: 67 additions & 24 deletions R/create_pkg.R
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,
#'
#' )
#'
#'
#' )
11 changes: 11 additions & 0 deletions R/logging.R
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 added R/options.R
Empty file.
9 changes: 9 additions & 0 deletions R/pkgdev-package.R
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
23 changes: 23 additions & 0 deletions R/readme.R
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 added dev/notes/API Client Package.md
Empty file.
Empty file added dev/notes/Data Package.md
Empty file.
53 changes: 53 additions & 0 deletions dev/notes/Database Helper Functions.md
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 added dev/notes/Database Package.md
Empty file.
Empty file.
Empty file added dev/notes/DevContainers.md
Empty file.
20 changes: 20 additions & 0 deletions dev/notes/GitHub Actions.md
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 added dev/notes/Internal Package.md
Empty file.
Loading

0 comments on commit dd63f6c

Please sign in to comment.