Skip to content

Commit

Permalink
Merge pull request #12 from PetterHopp/main
Browse files Browse the repository at this point in the history
OKplan v0.6.1
  • Loading branch information
PetterHopp authored Oct 9, 2023
2 parents df0e7a1 + 7517864 commit eb95fbb
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 20 deletions.
40 changes: 37 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -35,6 +35,7 @@ Imports:
OKcheck
Suggests:
covr,
desc,
devtools,
testthat,
usethis,
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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)
----------------------------------------

Expand Down
17 changes: 17 additions & 0 deletions OKplan.Rproj
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions R/adjust_samples_to_budget.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) %>%
Expand Down
2 changes: 1 addition & 1 deletion R/get_tested_herds.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 18 additions & 2 deletions R/write_ok_selection_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ 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(' <img src="man/figures/', NVIpkg, '_logo.png" align="right" height="138" />')
}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

`r paste0(NVIpkg, ": ", desc::desc_get_field(key = "Title"))`
`r paste0(NVIpkg, ": ", desc::desc_get_field(key = "Title"), logo_path)`
================

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <img src="man/figures/OKplan_logo.png" align="right" height="138" />

<!-- README.md is generated from README.Rmd. Please edit that file -->

Expand Down Expand Up @@ -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.
Expand Down
Binary file added man/figures/OKplan_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion man/write_ok_selection_list.Rd

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

13 changes: 11 additions & 2 deletions notes/develop.R
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions vignettes/NVI_vignette_style.css
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit eb95fbb

Please sign in to comment.