diff --git a/.gitignore b/.gitignore index 6d6372a..191a0a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,41 @@ -.Rproj.user +# History files .Rhistory +.Rapp.history + +# Session Data files .RData + +# User-specific files .Ruserdata -*.Rproj -*.Rcheck + +# Example code in package build process +*-Ex.R + +# Output files from R CMD build +/*.tar.gz + +# Output files from R CMD check +/*.Rcheck/ + +# RStudio files +.Rproj.user/ + +# produced vignettes +vignettes/*.html +vignettes/*.pdf + +# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +.httr-oauth + +# knitr and R markdown default cache directories +*_cache/ +/cache/ + +# Temporary files created by R markdown +*.utf8.md +*.knit.md + +# R Environment Variables +.Renviron + inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index ea2d8eb..1be864c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: OKplan Title: Tools to facilitate the Planning of the annual Surveillance Programmes -Version: 0.6.0 -Date: 2023-05-30 +Version: 0.6.1 +Date: 2023-10-09 Authors@R: c(person(given = "Petter", family = "Hopp", @@ -35,6 +35,7 @@ Imports: OKcheck Suggests: covr, + desc, devtools, testthat, usethis, diff --git a/LICENSE b/LICENSE index 780916a..a527b52 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2020, Norwegian Veterinary Institute +Copyright (c) 2020 - 2023 Norwegian Veterinary Institute All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/NEWS b/NEWS index 4d8eae3..e0dc484 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,18 @@ +OKplan 0.6.1 - (2023-10-09) +---------------------------------------- + +Bug fixes: + +- the argument `year` in `get_tested_herds` now accepts more than one year as input. + +- The argument column can now be passed to append_sum_line. + + +Other changes: + +- Updated help section in README + + OKplan 0.6.0 - (2023-05-30) ---------------------------------------- diff --git a/OKplan.Rproj b/OKplan.Rproj new file mode 100644 index 0000000..21a4da0 --- /dev/null +++ b/OKplan.Rproj @@ -0,0 +1,17 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/R/adjust_samples_to_budget.R b/R/adjust_samples_to_budget.R index bc15a32..2a8186a 100644 --- a/R/adjust_samples_to_budget.R +++ b/R/adjust_samples_to_budget.R @@ -118,10 +118,10 @@ adjust_samples_to_budget <- function(data, difference <- difference %>% dplyr::mutate(original_order = 1:dplyr::n()) %>% - dplyr::arrange(dplyr::across(c(group, sample_to_adjust))) %>% + dplyr::arrange(dplyr::across(dplyr::all_of(c(group, sample_to_adjust)))) %>% dplyr::group_by(dplyr::across(dplyr::all_of(group))) %>% dplyr::mutate(total_estimated = sum(dplyr::across(dplyr::all_of(sample_to_adjust)), na.rm = TRUE)) %>% - dplyr::mutate(included = dplyr::case_when(dplyr::across(sample_to_adjust) > 0 ~ 1, + dplyr::mutate(included = dplyr::case_when(dplyr::across(dplyr::all_of(sample_to_adjust)) > 0 ~ 1, TRUE ~ 0)) %>% dplyr::mutate(n_units = sum(.data$included, na.rm = TRUE)) %>% dplyr::mutate(difference = .data$total_estimated - as.numeric(.data$budget)) %>% diff --git a/R/get_tested_herds.R b/R/get_tested_herds.R index f36f440..d5f475e 100644 --- a/R/get_tested_herds.R +++ b/R/get_tested_herds.R @@ -62,7 +62,7 @@ get_tested_herds <- function(eos_table, checkmate::assert_integerish(year, lower = 1995, upper = (as.numeric(format(Sys.Date(), "%Y"))), any.missing = FALSE, all.missing = FALSE, - len = 1, + min.len = 1, add = checks) checkmate::assert_character(species, min.len = 1, null.ok = TRUE, add = checks) checkmate::assert_character(production, min.len = 1, null.ok = TRUE, add = checks) diff --git a/R/write_ok_selection_list.R b/R/write_ok_selection_list.R index 6a18e84..3d89622 100644 --- a/R/write_ok_selection_list.R +++ b/R/write_ok_selection_list.R @@ -41,6 +41,13 @@ #' #' All vectors must have the same order and the same length. #' +#' When \code{\link{calculate_sum}} is TRUE, a line with the sum will be appended. +#' The default is to calculate the sum of the column "ant_prover". If the sum +#' should be calculated for one or more other columns, you may give thecolumn +#' names as input to the argument \code{column} that will be passed to +#' \code{\link{append_sum_line}}. The sum will only be appended for columns +#' that exist in the data. +#' #' When more than one worksheet should be added to a single workbook, #' use \code{add_worksheet = FALSE} for the first worksheet and #' \code{add_worksheet = TRUE} for the consecutive worksheet(s). @@ -70,6 +77,7 @@ #' @param add_worksheet [\code{logical(1)}]\cr #' Should a worksheet be added to an existing workbook? Defaults to #' \code{FALSE}. +#' @param \dots Other arguments to be passed to \code{\link{append_sum_line}}. #' @export #' write_ok_selection_list <- function(data, @@ -81,11 +89,13 @@ write_ok_selection_list <- function(data, footnote = NULL, footnote_heights = NULL, dbsource, - add_worksheet = FALSE) { + add_worksheet = FALSE, + ...) { # PREPARE ARGUMENTS BEFORE ARGUMENT CHECKING ---- # Remove trailing backslash or slash before testing path filepath <- sub("\\\\{1,2}$|/{1,2}$", "", filepath) + dots <- list(...) # ARGUMENT CHECKING ---- # Object to store check-results @@ -179,7 +189,13 @@ write_ok_selection_list <- function(data, # INCLUDE EXTRA INFORMATION ---- # Append sum if (isTRUE(calculate_sum)) { - okdata <- append_sum_line(data = okdata, column = c("ant_prover"), position = "left") + if ("column" %in% names(dots)) { + column <- dots$column + } else {column <- "ant_prover"} + column <- intersect(column, colnames(data)) + if (length(column) > 0) { + okdata <- append_sum_line(data = okdata, column = column, position = "left") + } } # Append date generated diff --git a/README.Rmd b/README.Rmd index c538662..6060b78 100644 --- a/README.Rmd +++ b/README.Rmd @@ -6,13 +6,19 @@ output: params: NVIpkg: "OKplan" + pkg_path: !r usethis::proj_path() first_copyright_year: "2021" --- ```{r, include = FALSE} NVIpkg <- params$NVIpkg -# NVIpkg <- stringi::stri_extract_last_words(usethis::proj_path()) NVIpkg_inline <- paste0("`", NVIpkg, "`") +pkg_path <- params$pkg_path + +logo_path <- "" +if (file.exists(paste0("./man/figures/", NVIpkg, "_logo.png"))) { + logo_path <- paste0(' ') +} knitr::opts_chunk$set( collapse = TRUE, @@ -20,7 +26,7 @@ knitr::opts_chunk$set( ) ``` -`r paste0(NVIpkg, ": ", desc::desc_get_field(key = "Title"))` +`r paste0(NVIpkg, ": ", desc::desc_get_field(key = "Title"), logo_path)` ================ diff --git a/README.md b/README.md index de80641..74c812d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OKplan: Tools to facilitate the Planning of the annual Surveillance Programmes +# OKplan: Tools to facilitate the Planning of the annual Surveillance Programmes @@ -55,17 +55,34 @@ The `OKplan` package needs to be attached. surveillance programmes. The main focus is tools for generating standardized lists for NFSA. +#### Further documentation + +##### Help + The full list of all available functions and datasets can be accessed by typing help(package = "OKplan") -Please check the NEWS for information on new features, bug fixes and -other changes. +##### Vignettes + +Consult the vignettes for task-oriented help. + + vignette(package = "OKplan") + +Vignettes in package `OKplan`: + +- Contribute to OKplan (html) + +##### NEWS + +Please check the +[NEWS](https://github.com/NorwegianVeterinaryInstitute/OKplan/blob/main/NEWS) +for information on new features, bug fixes and other changes. ## Copyright and license -Copyright (c) 2021 - 2022 Norwegian Veterinary Institute. +Copyright (c) 2021 - 2023 Norwegian Veterinary Institute. Licensed under the BSD\_3\_clause License. See [License](https://github.com/NorwegianVeterinaryInstitute/OKplan/blob/main/LICENSE) for details. diff --git a/man/figures/OKplan_logo.png b/man/figures/OKplan_logo.png new file mode 100644 index 0000000..f7e56ef Binary files /dev/null and b/man/figures/OKplan_logo.png differ diff --git a/man/write_ok_selection_list.Rd b/man/write_ok_selection_list.Rd index 6abab1e..583934e 100644 --- a/man/write_ok_selection_list.Rd +++ b/man/write_ok_selection_list.Rd @@ -14,7 +14,8 @@ write_ok_selection_list( footnote = NULL, footnote_heights = NULL, dbsource, - add_worksheet = FALSE + add_worksheet = FALSE, + ... ) } \arguments{ @@ -52,6 +53,8 @@ be used for standardising and formatting the sampling plan output.} \item{add_worksheet}{[\code{logical(1)}]\cr Should a worksheet be added to an existing workbook? Defaults to \code{FALSE}.} + +\item{\dots}{Other arguments to be passed to \code{\link{append_sum_line}}.} } \description{ The sampling plan is output to an Excel sheet. The list with @@ -97,6 +100,13 @@ The list input to column_standards must follow a specific format. All vectors must have the same order and the same length. +When \code{\link{calculate_sum}} is TRUE, a line with the sum will be appended. + The default is to calculate the sum of the column "ant_prover". If the sum + should be calculated for one or more other columns, you may give thecolumn + names as input to the argument \code{column} that will be passed to + \code{\link{append_sum_line}}. The sum will only be appended for columns + that exist in the data. + When more than one worksheet should be added to a single workbook, use \code{add_worksheet = FALSE} for the first worksheet and \code{add_worksheet = TRUE} for the consecutive worksheet(s). diff --git a/notes/develop.R b/notes/develop.R index 32ffcf9..9d33ebd 100644 --- a/notes/develop.R +++ b/notes/develop.R @@ -16,12 +16,19 @@ pkg <- stringi::stri_extract_last_words(pkg_path) # CREATE PACKAGE SKELETON ---- -# create_NVIpkg_skeleton(license_keyword = "CC BY 4.0") +# create_NVIpkg_skeleton(license_keyword = "BSD_3_clause") # BSD_3_clause # CC BY 4.0 # INCREASE PACKAGE VERSION IN DESCRIPTION AND NEWS ---- # NVIpackager::increase_NVIpkg_version(pkg = pkg, # pkg_path = pkg_path, -# type = "develop") +# type = "develop", +# document = FALSE) + +# UPDATE LICENSE +# NVIpackager::update_license(pkg = pkg, +# pkg_path = pkg_path, +# copyright_owner = "Norwegian Veterinary Institute") + # DOCUMENTATION AND STYLING ---- # update_logo should be run if a logo has been created (or updated). Thereafter run "document_NVIpkg" with "readme = TRUE". @@ -36,6 +43,8 @@ NVIpackager::document_NVIpkg(pkg = pkg, readme = FALSE, manual = "update", scope = c("spaces", "line_breaks")) +# filename <- "xxxx.R" +# styler::style_file(path = file.path(pkg_path, "R", filename), scope = I(c("spaces"))) # spelling::spell_check_package(vignettes = TRUE, use_wordlist = TRUE) diff --git a/vignettes/NVI_vignette_style.css b/vignettes/NVI_vignette_style.css new file mode 100644 index 0000000..d600561 --- /dev/null +++ b/vignettes/NVI_vignette_style.css @@ -0,0 +1,11 @@ +h1, h2, h3, h4 { + color: #1b314f; + font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; +} +body { + color: #1b314f; + font-family: "source-serif-pro", "merriweather", serif; +} +thead { + font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; +}