From 790054ac2424ba758a126e3e4d27537e31d079b8 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Sat, 26 Jun 2021 12:43:27 +0200 Subject: [PATCH 01/28] chore: DESCRIPTION and NEWS Updated licence and copyright. Corrected reference to github packages in DESCRIPTION --- DESCRIPTION | 20 +++++++++++++------- NEWS | 12 ++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 19f9482..08207f3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,14 @@ Package: OKplan Title: Tools facilitating the planning of surveillance programmes for the NFSA -Version: 0.2.0 -Date: 2021-01-29 -Author: Petter Hopp -Maintainer: Petter Hopp +Version: 0.2.1 +Date: 2021-04-## +Authors@R: + c(person(given = "Petter", + family = "Hopp", + role = c("aut", "cre"), + email = "Petter.Hopp@vetinst.no"), + person(given = "Norwegian Veterinary Institute", + role = "cph")) Description: The R-package include tools facilitating the planning of surveillance programmes for the Norwegian Food Safety Authority. The package is under development. Included will be tools for: @@ -12,13 +17,13 @@ Description: The R-package include tools facilitating the planning of surveillan 3) generate lists for the NFSA. URL: https://github.com/NorwegianVeterinaryInstitute/OKplan BugReports: https://github.com/NorwegianVeterinaryInstitute/OKplan/issues -Depends: R (>= 3.4.1) -License: Proprietary. Do not distribute outside the Norwegian Veterinary Institute +Depends: R (>= 3.5.0) +License: BSD_3_clause + file LICENSE Encoding: UTF-8 LazyData: true Imports: poorman, - NVIdb, + NVIdb (>= 0.3.0), checkmate RoxygenNote: 7.1.1 Suggests: @@ -31,5 +36,6 @@ Suggests: styler, knitr, rmarkdown +Remotes: NorwegianVeterinaryInstitute/NVIdb VignetteBuilder: knitr Language: en-GB diff --git a/NEWS b/NEWS index 08deedf..2d599f8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,15 @@ +OKplan 0.2.1 - (2021-04-##) +-------------------------- + +Bug fixes: + +- Included reference to NVIdb at GitHub to correct potential problems when installing the package. + +Other changes: + + - Updated licence to BSD-3 and copyright Holder to Norwegian Veterinary Institute. + + OKplan 0.2.0 - (2021-01-29) -------------------------- From 2e731bef4b0e8ae86e8cfee42798f3ef8aa2f986 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Tue, 23 Nov 2021 16:19:24 +0100 Subject: [PATCH 02/28] doc: Added CONTRIBUTING.md and vignette Contribute_to_OKplan.Rmd --- CONTRIBUTING.md | 214 +++++++++++++++++++++++++++++ vignettes/.gitignore | 2 + vignettes/Contribute_to_OKplan.Rmd | 137 ++++++++++++++++++ 3 files changed, 353 insertions(+) create mode 100644 CONTRIBUTING.md create mode 100644 vignettes/.gitignore create mode 100644 vignettes/Contribute_to_OKplan.Rmd diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b11d420 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,214 @@ +# Contribute to OKplan + + + +Thank you for considering contributing to `OKplan`. + +`OKplan` is one of several packages assembled under the name `NVIverse`, +a collection of R-packages with tools to facilitate data management and +data reporting at the Norwegian Veterinary Institute (NVI). + +### NVIverse packages + + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PackageStatusDescription
NVIconfigPrivateConfiguration information necessary for some NVIverse functions
NVIdbPublicTools to facilitate the use of NVI’s databases
NVIprettyPublicTools to make R-output pretty in accord with NVI’s graphical profile
NVIbatchPublicTools to facilitate the running of R-scripts in batch mode at NVI
OKplanPublicTools to facilitate the planning of surveillance programmes for the NFSA
OKcheckPublicTools to facilitate checking of data from national surveillance programmes
NVIcheckmatePublicExtension of checkmate with argument checking adapted for NVIverse
NVIpackagerPublicTools to facilitate the development of NVIverse packages
+ +How you can contribute +---------------------- + +There are several ways you can contribute to this project: ask a +question, propose an idea, report a bug, improve the documentation, or +contribute code. + +### Ask a question + +Using `OKplan` and need help? Browse the package help to see if you can +find a solution. Still problems? Post your question in R-forum at +workplace or contact the package maintainer by +[email](mailto:petter.hopp@vetinst.no). + +### Propose an idea + +Have an idea for a new `OKplan` feature? Take a look at the `OKplan` +help and [issue +list](https://github.com/NorwegianVeterinaryInstitute/OKplan/issues) to +see if it isn’t included or suggested yet. If not, suggest your idea as +an [issue on +GitHub](https://github.com/NorwegianVeterinaryInstitute/OKplan/issues/new). +While we can’t promise to implement your idea, it helps to: + +- Explain in detail how it would work. +- Keep the scope as narrow as possible. + +See below if you want to contribute code for your idea as well. + +### Report a bug + +Using `OKplan` and discovered a bug? Don’t let others have the same +experience and report it as an [issue on +GitHub](https://github.com/NorwegianVeterinaryInstitute/OKplan/issues/new) +so we can fix it. A good bug report makes it easier for us to do so, so +please include: + +- Any details about your local setup that might be helpful in + troubleshooting. +- Detailed steps to reproduce the bug. + +### Improve the documentation + +Noticed a typo on the function help? Think a function could use a better +example? Good documentation makes all the difference, so your help to +improve it is very welcome! + +Functions are described as comments near their code and translated to +documentation using [`roxygen2`](https://klutometis.github.io/roxygen/). +If you want to improve a function description: + +1. Go to `R/` directory in the [code + repository](https://github.com/NorwegianVeterinaryInstitute/OKplan/tree/main/R). +2. Look for the file with the name of the function. +3. [Propose a file + change](https://help.github.com/articles/editing-files-in-another-user-s-repository/) + to update the function documentation in the roxygen comments + (starting with `#'`). + +### Contribute code + +Care to fix bugs or implement new functionality for our\_package? Great! +Have a look at the [issue +list](https://github.com/NorwegianVeterinaryInstitute/OKplan/issues) and +leave a comment on the things you want to work on. See also the +development guidelines below. + +Development guidelines +---------------------- + +If you want to contribute code, you are welcome to do so. Please try to +adhere to some principles and style convention used for +`NVIverse`-packages. + +- Please limit the number of package dependencies for `OKplan`. The + use of base functions is much appreciated. + +- New code should generally follow the tidyverse [style + guide](http://style.tidyverse.org). I recommend to use the + [`styler`](https://CRAN.R-project.org/package=styler) package to + apply spaces: `styler::style_file(filename, scope = "spaces")`. + Please don’t restyle code that has nothing to do with your pull + request. + +- You should add a bullet point to `NEWS` motivating the change. + +- You should add yourself as a contributor to the `DESCRIPTION`. + +- If you’re adding a new function or new arguments to an existing + function, you’ll also need to document them. `NVIverse`-packages use + [`roxygen2`](https://cran.r-project.org/package=roxygen2), with + [Markdown + syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/markdown.html), + for documentation. Make sure to re-run `devtools::document()` on the + code before submitting. + +- `NVIverse`-packages use the assert-functions from + [`checkmate`](https://CRAN.R-project.org/package=checkmate) package + for argument checking as well as some additional assert\_functions + in + [`NVIcheckmate`](https://github.com/NorwegianVeterinaryInstitute/NVIcheckmate). + Adding argument checking for new functions and/or arguments will be + highly appreciated. + +- If you can, also write a test. `NVIverse`-packages use + [`testthat`](https://cran.r-project.org/package=testthat) for tests. + +- Also run `devtools::check()` to make sure your function doesn’t + imply downstream errors or warnings. + +### Git commit standards + +We follow the commit message style guide maintained within the +angular.js project. + +The start of commit messages should be one of the following: + +- feat: A new feature +- fix: A bug fix +- doc: Documentation only changes +- style: Changes that do not affect the meaning of the code + (white-space, formatting, missing semi-colons, etc) +- refactor: A code change that neither fixes a bug or adds a feature +- perf: A code change that improves performance +- test: Adding missing tests +- chore: Changes to the build process or auxiliary tools and libraries + such as documentation generation + +Do not capitalize the first letter. + +Code of conduct +--------------- + +Please note that this project is released with a [Contributor Code of +Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). +By participating to this project, you agree to abide by its terms. + +References +---------- + +This document is adapted from a +[template](https://gist.github.com/peterdesmet/e90a1b0dc17af6c12daf6e8b2f044e7c) +by @peterdesmet . diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/Contribute_to_OKplan.Rmd b/vignettes/Contribute_to_OKplan.Rmd new file mode 100644 index 0000000..d0199ba --- /dev/null +++ b/vignettes/Contribute_to_OKplan.Rmd @@ -0,0 +1,137 @@ +--- +output: + rmarkdown::html_vignette: + keep_md: true +md_document: + variant: markdown_github + +params: + NVIpkg: "OKplan" +title: "Contribute to `r params$NVIpkg`" + +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{Contribute to OKplan} + %\VignetteEncoding + +--- + + +```{r, include = FALSE} +NVIpkg <- params$NVIpkg +NVIpkg_inline <- paste0("`", NVIpkg, "`") +NVIpkg_code <- "/tree/main/R" +# pkg_name <- NVIpkg_inline +# pkg_name <- "`NVIcheckmate`" +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) + +``` + + + +Thank you for considering contributing to `r NVIpkg_inline`. + +`r NVIpkg_inline` is one of several packages assembled under the name `NVIverse`, a collection of R-packages with tools to facilitate data management and data reporting at the Norwegian Veterinary Institute (NVI). + +### NVIverse packages +```{r echo = FALSE, results = 'asis'} +library(NVIpackager) +knitr::kable(x = NVIpackages) +``` + +## How you can contribute +There are several ways you can contribute to this project: ask a question, propose an idea, report a bug, improve the documentation, or contribute code. + +### Ask a question + +Using `r NVIpkg_inline` and need help? Browse the package help to see if you can find a solution. Still problems? Post your question in R-forum at workplace or contact the package maintainer by [email](mailto:petter.hopp@vetinst.no). + +### Propose an idea + +Have an idea for a new `r NVIpkg_inline` feature? Take a look at the `r NVIpkg_inline` help and `r paste0("[issue list](https://github.com/NorwegianVeterinaryInstitute/",NVIpkg, "/issues)")` to see if it isn't included or suggested yet. If not, suggest your idea as an `r paste0("[issue on GitHub](https://github.com/NorwegianVeterinaryInstitute/",NVIpkg, "/issues/new)")`. While we can't promise to implement your idea, it helps to: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible. + +See below if you want to contribute code for your idea as well. + +### Report a bug + +Using `r NVIpkg_inline` and discovered a bug? Don't let others have the same experience and report it as an `r paste0("[issue on GitHub](https://github.com/NorwegianVeterinaryInstitute/",NVIpkg, "/issues/new)")` so we can fix it. A good bug report makes it easier for us to do so, so please include: + +* Any details about your local setup that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. + +### Improve the documentation + +Noticed a typo on the function help? Think a function could use a better example? Good documentation makes all the difference, so your help to improve it is very welcome! + +Functions are described as comments near their code and translated to documentation using [`roxygen2`](https://klutometis.github.io/roxygen/). If you want to improve a function description: + +1. Go to `R/` directory in the `r paste0("[code repository](https://github.com/NorwegianVeterinaryInstitute/",NVIpkg, NVIpkg_code,")")`. +2. Look for the file with the name of the function. +3. [Propose a file change](https://help.github.com/articles/editing-files-in-another-user-s-repository/) to update the function documentation in the roxygen comments (starting with `#'`). + +### Contribute code + +Care to fix bugs or implement new functionality for our_package? Great! Have a look at the `r paste0("[issue list](https://github.com/NorwegianVeterinaryInstitute/",NVIpkg, "/issues)")` and leave a comment on the things you want to work on. See also the development guidelines below. + + +## Development guidelines + +If you want to contribute code, you are welcome to do so. Please try to adhere +to some principles and style convention used for `NVIverse`-packages. + +* Please limit the number of package dependencies for `r NVIpkg_inline`. The use of base +functions is much appreciated. + +* New code should generally follow the tidyverse [style guide](http://style.tidyverse.org). +I recommend to use the [`styler`](https://CRAN.R-project.org/package=styler) +package to apply spaces: `styler::style_file(filename, scope = "spaces")`. +Please don't restyle code that has nothing to do with your pull request. + +* You should add a bullet point to `NEWS` motivating the change. + +* You should add yourself as a contributor to the `DESCRIPTION`. + +* If you're adding a new function or new arguments to an existing function, you'll also need + to document them. `NVIverse`-packages use [`roxygen2`](https://cran.r-project.org/package=roxygen2), with +[Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/markdown.html), +for documentation. Make sure to re-run `devtools::document()` on the code before submitting. + +* `NVIverse`-packages use the assert-functions from [`checkmate`](https://CRAN.R-project.org/package=checkmate) package for argument checking as well as some additional assert_functions in [`NVIcheckmate`](https://github.com/NorwegianVeterinaryInstitute/NVIcheckmate). Adding argument checking for new functions and/or arguments will be highly appreciated. + +* If you can, also write a test. `NVIverse`-packages use [`testthat`](https://cran.r-project.org/package=testthat) for tests. + +* Also run `devtools::check()` to make sure your function doesn't imply downstream errors or warnings. + + +### Git commit standards +We follow the commit message style guide maintained within the angular.js project. + +The start of commit messages should be one of the following: + +* feat: A new feature +* fix: A bug fix +* doc: Documentation only changes +* style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) +* refactor: A code change that neither fixes a bug or adds a feature +* perf: A code change that improves performance +* test: Adding missing tests +* chore: Changes to the build process or auxiliary tools and libraries such as documentation generation + +Do not capitalize the first letter. + + +## Code of conduct +Please note that this project is released with a +[Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By participating to this project, you agree to abide by its terms. + + +## References +This document is adapted from a [template](https://gist.github.com/peterdesmet/e90a1b0dc17af6c12daf6e8b2f044e7c) by @peterdesmet . From 34803920969af016785522245dc1650d1b4a0fc4 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Tue, 23 Nov 2021 16:20:18 +0100 Subject: [PATCH 03/28] feat: included adjust_sample_number --- NAMESPACE | 1 + R/adjust_sample_number.R | 55 +++++++++++++++++++++++++++++++++++++ man/adjust_sample_number.Rd | 39 ++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 R/adjust_sample_number.R create mode 100644 man/adjust_sample_number.Rd diff --git a/NAMESPACE b/NAMESPACE index f39f8dd..c4b8216 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(adjust_sample_number) export(control_OK_selection) export(include_generated_date) export(make_random) diff --git a/R/adjust_sample_number.R b/R/adjust_sample_number.R new file mode 100644 index 0000000..c8cc277 --- /dev/null +++ b/R/adjust_sample_number.R @@ -0,0 +1,55 @@ +#' @title Adjust the sample size per selected unit +#' @description Adds new column with an adjusted the sample size per selected +#' unit. The total sample size is adjusted to be in accord with the total +#' budgetted sample size. +#' +#' @details The sample size should first be estimated by percentage or similar. +#' +#' @param data Data frame +#' @param budget The total budgeted sample number. +#' @param col_estimated The name of the column with the sample size per unit that should be adjusted. +#' @param col_adjusted The name of the column with the adjusted sample size per unit. +#' @param adjust_by The maximum number of samples that one should adjust by. +#' +#' @return A data frame with a new column with an adjusted sample number. +#' +#' @author Petter Hopp Petter.Hopp@@vetinst.no +#' @export +#' + +adjust_sample_number <- function(data, budget, col_estimated, col_adjusted = "justert_ant_prover", adjust_by) { + + # Justerer prøvetallet opp eller ned + total_estimated <- sum(data[, col_estimated], na.rm = TRUE) + + difference <- c(as.numeric(total_estimated - budget) ,rep(NA, dim(data)[1] - 1)) + + # Order data with largest sample size first + data <- data[order(data[, col_estimated], decreasing = TRUE), ] + + # Only justify sample number when there is disagreement between budget and calculated number of samples + if (total_estimated != budget) { + # Adjust for each sampled unit with the unit having the largest sample size first + for (i in c(1:dim(data)[1])) { + + # Justify by positive or negative number depending on whether sample size is too small or too large. + # If the difference is larger than adjust_by, then adjust by adjust_by + # Else adjust by 1 | -1 + # If no difference "adjust by" 0 + if (abs(difference[i]) > adjust_by) { + justify <- ifelse(difference[i] > 0, -adjust_by, adjust_by) + } else { + justify <- ifelse(difference[i] > 0, -1, 1) + } + if (difference[i] == 0) {justify <- 0} + + # Make new column with + data[i, col_adjusted] <- data[i, col_estimated] + justify + if (i < dim(data)[1]) { + difference[i+1] <- difference[i] + justify + } + + } + } + return(data) +} diff --git a/man/adjust_sample_number.Rd b/man/adjust_sample_number.Rd new file mode 100644 index 0000000..6d76596 --- /dev/null +++ b/man/adjust_sample_number.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/adjust_sample_number.R +\name{adjust_sample_number} +\alias{adjust_sample_number} +\title{Adjust the sample size per selected unit} +\usage{ +adjust_sample_number( + data, + budget, + col_estimated, + col_adjusted = "justert_ant_prover", + adjust_by +) +} +\arguments{ +\item{data}{Data frame} + +\item{budget}{The total budgeted sample number.} + +\item{col_estimated}{The name of the column with the sample size per unit that should be adjusted.} + +\item{col_adjusted}{The name of the column with the adjusted sample size per unit.} + +\item{adjust_by}{The maximum number of samples that one should adjust by.} +} +\value{ +A data frame with a new column with an adjusted sample number. +} +\description{ +Adds new column with an adjusted the sample size per selected + unit. The total sample size is adjusted to be in accord with the total + budgetted sample size. +} +\details{ +The sample size should first be estimated by percentage or similar. +} +\author{ +Petter Hopp Petter.Hopp@vetinst.no +} From bb93b8d0ed4f2a0ffa2a03ab827bf415ebb99043 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Tue, 23 Nov 2021 16:20:58 +0100 Subject: [PATCH 04/28] test: fixed test_OK_column_standards --- tests/testthat/test_OK_column_standards.R | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/testthat/test_OK_column_standards.R b/tests/testthat/test_OK_column_standards.R index 899e295..e974f25 100644 --- a/tests/testthat/test_OK_column_standards.R +++ b/tests/testthat/test_OK_column_standards.R @@ -6,27 +6,27 @@ context("OK_column_standards") test_that("Standard colwidths in Excel for OK-selections", { # Generate data frame with column names for table that should be exported to Excel # Example with selection of samples collected in herds - df <- cbind("ok_aar" = "2021", "rapport" = "Brucellose hos geit, utvalgsliste", - "mt_regionnr" = "M22000", "mt_region" = " Region Øst ", - "mt_avdelingnr" = " M22110", "mt_avdeling" = " Glåmdal og Østerdal ", - "eier_lokalitetnr" = "34343434", "eier_lokalitet" = "Gårdsbruk", "postnr" = "2560", "poststed" = " ALVDAL ", - "ant_prover" = 30) + df <- as.data.frame(cbind("ok_aar" = "2021", "rapport" = "Brucellose hos geit, utvalgsliste", + "mt_regionnr" = "M22000", "mt_region" = " Region Øst ", + "mt_avdelingnr" = " M22110", "mt_avdeling" = " Glåmdal og Østerdal ", + "eier_lokalitetnr" = "34343434", "eier_lokalitet" = "Gårdsbruk", "postnr" = "2560", "poststed" = " ALVDAL ", + "ant_prover" = 30)) # Make a vector with correct column names after translation - correct_result <- c(5, 10.78, 12.5, 16, 13, 33, 12, 30, 8, 15, 8.5) + correct_result <- c(5, 10.71, 12.5, 16, 13, 33, 12, 30, 8, 15, 8.5) # Compare Add fylke, current fylkenr and current fylke with correct result expect_equal(standardize_columns(data = df, dbsource = "geit_brucella_utvalg", - standards = OK_column_standards, + standards = OK_column_standards, property = "colwidths_Excel"), correct_result) # Generate data frame with column names for table that should be exported to Excel # Example with selection of samples collected at slaughterhouses - df <- cbind("mt_regionnr" = "M25000", "mt_region" = "Region Nord", - "mt_avdelingnr" = "M25150", "mt_avdeling" = "Finnmark", - "eier_lokalitetnr" = "802", "eier_lokalitet" = "NORTURA SA AVD. FINNMARK/KARASJOK", - "ant_prover" = 30) + df <- as.data.frame(cbind("mt_regionnr" = "M25000", "mt_region" = "Region Nord", + "mt_avdelingnr" = "M25150", "mt_avdeling" = "Finnmark", + "eier_lokalitetnr" = "802", "eier_lokalitet" = "NORTURA SA AVD. FINNMARK/KARASJOK", + "ant_prover" = 30)) # Make a vector with correct column names after translation @@ -44,11 +44,11 @@ test_that("Standard colwidths in Excel for OK-selections", { test_that("Standard collabels for OK selections", { # Example with selection of samples collected in herds - df <- cbind("aar" = "2021", "rapport" = "Paratuberkulose hos storfe, utvalgsliste", - "mt_regionnr" = "M21000", "mt_region" = " Region Stor-Oslo", - "mt_avdelingnr" = "M21130", "mt_avdeling" = "Østfold og Follo", - "eier_lokalitetnr" = "3030303030", "eier_lokalitet" = "Gårdsbruk", "postnr" = "1747", "poststed" = "SKJEBERG", - "ant_prover" = 5, "provetakingstidspunkt" = 2) + df <- as.data.frame(cbind("aar" = "2021", "rapport" = "Paratuberkulose hos storfe, utvalgsliste", + "mt_regionnr" = "M21000", "mt_region" = " Region Stor-Oslo", + "mt_avdelingnr" = "M21130", "mt_avdeling" = "Østfold og Follo", + "eier_lokalitetnr" = "3030303030", "eier_lokalitet" = "Gårdsbruk", "postnr" = "1747", "poststed" = "SKJEBERG", + "ant_prover" = 5, "provetakingstidspunkt" = 2)) # Make a vector with correct column names after translation correct_result <- c("År", "Rapport", "MT regionnr", "MT region", "MT avdelingsnr", "MT avdeling", "Produsentnr", @@ -63,10 +63,10 @@ test_that("Standard collabels for OK selections", { # Generate column labels # Example with selection of samples collected at slaughterhouses - df <- cbind("mt_regionnr" = "M25000", "mt_region" = "Region Nord", - "mt_avdelingnr" = "M25150", "mt_avdeling" = "Finnmark", - "eier_lokalitetnr" = "802", "eier_lokalitet" = "NORTURA SA AVD. FINNMARK/KARASJOK", - "ant_prover" = 30) + df <- as.data.frame(cbind("mt_regionnr" = "M25000", "mt_region" = "Region Nord", + "mt_avdelingnr" = "M25150", "mt_avdeling" = "Finnmark", + "eier_lokalitetnr" = "802", "eier_lokalitet" = "NORTURA SA AVD. FINNMARK/KARASJOK", + "ant_prover" = 30)) # Make a vector with correct column names after translation From e7bd9757e5309d41cfc421e9d19a8820d46cd618 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 08:19:19 +0100 Subject: [PATCH 05/28] chore: develop.R replaced build.R --- notes/build.R | 59 -------------------------------- notes/develop.R | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 59 deletions(-) delete mode 100644 notes/build.R create mode 100644 notes/develop.R diff --git a/notes/build.R b/notes/build.R deleted file mode 100644 index 45f2de3..0000000 --- a/notes/build.R +++ /dev/null @@ -1,59 +0,0 @@ -# TEST, DOCUMENT AND BUILD NVIdb PACKAGE - -# Set up environment -Rlibrary <- R.home() - -library(devtools) -library(roxygen2) -library(withr) - -# Creates new help files -# Should be run before git push when documentation for functions have been changed -devtools::document() - -# Run tests included in ./tests. NVIdb use thestthat -devtools::test() - -# Build the vignette -# devtools::build_vignettes() -# vignetteRDS <- readRDS("./Meta/vignette.rds") - -# devtools::build_manual() - -# Build the package -# system("R CMD build ../NVIdb") -devtools::build(binary = TRUE) -# devtools::build(binary = TRUE, manual = TRUE, vignettes = TRUE) - -# Extensive checking of package. Is done after build. Creates PDF-manual -system("R CMD check --ignore-vignettes ../OKplan") - -# Alternative for creating the PDF-manual. The manual is not put in the correct directory -# system(paste(shQuote(file.path(R.home("bin"), "R")), -# "CMD", -# "Rd2pdf", -# shQuote(paste0(Rlibrary,"/library/OKplan")))) - - - -# Innstall rebuilt package -detach("package:OKplan", unload=TRUE) - -with_libpaths(paste0(Rlibrary,"/library"), - install(sub("notes", "", dirname(rstudioapi::getSourceEditorContext()$path)), - dependencies = TRUE, - upgrade=FALSE, - build_vignettes = TRUE) -) - -# # Install from binary file -# remove.packages("OKplan") -# # install.packages("C:/Users/13hopp/Documents/GitProjects/OKplan_0.1.5.9000.zip", -# install.packages("C:/Users/13hopp/OneDrive - Veterinærinstituttet/R/OKplan_0.2.2.9002.zip", -# repos = NULL, -# type = "binary") - - -help(package="OKplan") -library(OKplan) - diff --git a/notes/develop.R b/notes/develop.R new file mode 100644 index 0000000..db5bd76 --- /dev/null +++ b/notes/develop.R @@ -0,0 +1,91 @@ +# TEST, DOCUMENT AND BUILD NVIdb PACKAGE + +# SET UP ENVIRONMENT ---- +# rm(list = ls()) # Benyttes for å tømme R-environment ved behov + +# Attach packages +# library(devtools) +# library(roxygen2) +library(NVIpackager) +library(spelling) + +# Global variables +pkg <- stringi::stri_extract_last_words(usethis::proj_path()) +pkg_path = usethis::proj_path() +# Rlibrary <- R.home() + +# create_NVIpkg_skeleton(license_keyword = "CC BY 4.0") + +# DOCUMENTATION AND STYLING ---- +# Creates new help files +# Should be run before git push when documentation for functions have been changed +NVIpackager::document_NVIpkg(style = FALSE, + contributing = FALSE, + readme = FALSE, + scope = c("spaces", "line_breaks")) + + +# spelling::spell_check_package(vignettes = TRUE, use_wordlist = TRUE) + + +# Alternative for creating the PDF-manual. The manual is not put in the correct directory +# system(paste(shQuote(file.path(R.home("bin"), "R")), +# "CMD", +# "Rd2pdf", +# paste0("../", pkg))) +# file.copy(from = paste0(pkg, ".pdf"), to = "./vignettes", overwrite = TRUE) +# file.remove(".Rd2pdf16372") +# file.remove("NVIdb.pdf") +# check .install_extras + +# TEST PACKAGE ---- +# Run tests included in ./tests. +devtools::test() + +# Test package coverage +# DETACH PACKAGE +# The package must be detached to install it. +if(pkg %in% (.packages())){ + pkgname <- paste0("package:", pkg) + detach(pkgname, unload=TRUE, character.only = TRUE) +} +code_coverage <- covr::package_coverage(path = ".", group = "functions") +print(x = code_coverage, group = "functions") + +# devtools::build_manual(pkg = "../NVIpackager", path = "./vignettes") + +# Build the package +devtools::build(binary = FALSE, manual = TRUE, vignettes = TRUE) +# Test built package. +# Thereby, no problems with files in .Rbuildignore. +version <- packageVersion(pkg, lib.loc = paste0(getwd(),"/..")) +devtools::check_built(path = paste0("../", pkg, "_", version, ".tar.gz"), args = c("--no-tests"), manual = TRUE) + +# Extensive checking of package. Is done after build. Creates PDF-manual +# system("R CMD check --ignore-vignettes ../NVIdb") + + +# INSTALL PACKAGE ---- + +NVIpackager::install_NVIpkg(pkg = pkg, pkg_path = pkg_path, rsource = "local") + +# NVIpackager::install_NVIpkg(pkg = pkg, pkg_path = pkg_path, rsource = "github", username = "PetterHopp") +# +# NVIpackager::install_NVIpkg(pkg = pkg, pkg_path = pkg_path, rsource = "github", username = "NorwegianVeterinaryInstitute") +# +# # # Install from source file in catalog "NVIverse" +# utils::install.packages(pkgs = paste0(NVIconfig:::path_NVI["NVIverse"], "/", pkg, "/Arkiv/", pkg, "_", version, ".tar.gz"), +# repos = NULL, +# type = "source") +# +# # Install from binary file in catalog "NVIverse" +# install.packages(pkgs = paste0(NVIconfig:::path_NVI["NVIverse"], "/", pkg, "/Arkiv/", pkg, "_", version, ".zip"), +# repos = NULL, +# type = "binary") + +# ATTACH PACKAGE ---- +utils::help(package = (pkg)) + +library(package = pkg, character.only = TRUE) + + From 7ba7a783367b179f202b73004affe9201cbd8506 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 08:21:26 +0100 Subject: [PATCH 06/28] refactor: updated make_random Styled help. Included param init_seed in help. Improved argument checking. Changed to stats::runif. --- R/make_random.R | 11 +++++++---- man/make_random.Rd | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/R/make_random.R b/R/make_random.R index 2a9bd52..5865b80 100644 --- a/R/make_random.R +++ b/R/make_random.R @@ -1,12 +1,15 @@ #' @title Add new column with random numbers #' @description Adds new column with random numbers. The function is built to be able to use it in piping. #' -#' @details To make reproducible random numbers the seed can be initialized with a specific value. The first time the seed is used, set \code{init_seed = TRUE}. -#' Thereafter, use \code{init_seed = FALSE} if more random numbers are generated in the session to avoid overlapping random numbers. +#' @details To make reproducible random numbers the seed can be initialized with a +#' specific value. The first time the seed is used, set \code{init_seed = TRUE}. +#' Thereafter, use \code{init_seed = FALSE} if more random numbers are generated +#' in the session to avoid overlapping random numbers. #' #' @param data Data frame #' @param colname The name of the new column with the random number. #' @param seed The initializing seed +#' @param init_seed Should the seed be initialized, defaults to FALSE. #' #' @return A data frame with a new column with a random variable. #' @@ -34,7 +37,7 @@ make_random <- function(data, colname = "random", seed = -1, init_seed = FALSE) # Argument checking checks <- checkmate::makeAssertCollection() checkmate::assert_data_frame(data, add = checks) - checkmate::assert_character(colname, add = checks) + checkmate::assert_character(colname, len = 1, min.chars = 1, any.missing = FALSE, add = checks) checkmate::assert_number(seed, add = checks) checkmate::assert_logical(init_seed, add = checks) checkmate::reportAssertions(checks) @@ -43,7 +46,7 @@ make_random <- function(data, colname = "random", seed = -1, init_seed = FALSE) if (init_seed == TRUE) {set.seed(seed)} # Generates new column with random numbers - data[, colname] <- runif(n = dim(data)[1]) + data[, colname] <- stats::runif(n = dim(data)[1]) return(data) } diff --git a/man/make_random.Rd b/man/make_random.Rd index c6998cb..997f3bc 100644 --- a/man/make_random.Rd +++ b/man/make_random.Rd @@ -12,6 +12,8 @@ make_random(data, colname = "random", seed = -1, init_seed = FALSE) \item{colname}{The name of the new column with the random number.} \item{seed}{The initializing seed} + +\item{init_seed}{Should the seed be initialized, defaults to FALSE.} } \value{ A data frame with a new column with a random variable. @@ -20,8 +22,10 @@ A data frame with a new column with a random variable. Adds new column with random numbers. The function is built to be able to use it in piping. } \details{ -To make reproducible random numbers the seed can be initialized with a specific value. The first time the seed is used, set \code{init_seed = TRUE}. - Thereafter, use \code{init_seed = FALSE} if more random numbers are generated in the session to avoid overlapping random numbers. +To make reproducible random numbers the seed can be initialized with a + specific value. The first time the seed is used, set \code{init_seed = TRUE}. + Thereafter, use \code{init_seed = FALSE} if more random numbers are generated + in the session to avoid overlapping random numbers. } \examples{ \dontrun{ From 1a285f9c3f85fa4b9d6b75ac6cae3003a1174682 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 08:23:30 +0100 Subject: [PATCH 07/28] refactor: Updated adjust_sample_number Changed parameters to sample_to_adjust and adjusted_sample. Included argument checking. Fixed typo. --- R/adjust_sample_number.R | 30 ++++++++++++++++++++++-------- man/adjust_sample_number.Rd | 10 +++++----- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/R/adjust_sample_number.R b/R/adjust_sample_number.R index c8cc277..8244f12 100644 --- a/R/adjust_sample_number.R +++ b/R/adjust_sample_number.R @@ -1,14 +1,14 @@ #' @title Adjust the sample size per selected unit #' @description Adds new column with an adjusted the sample size per selected #' unit. The total sample size is adjusted to be in accord with the total -#' budgetted sample size. +#' budgeted sample size. #' #' @details The sample size should first be estimated by percentage or similar. #' #' @param data Data frame #' @param budget The total budgeted sample number. -#' @param col_estimated The name of the column with the sample size per unit that should be adjusted. -#' @param col_adjusted The name of the column with the adjusted sample size per unit. +#' @param sample_to_adjust The name of the column with the sample number per unit that should be adjusted. +#' @param adjusted_sample The name of the column with the adjusted sample number per unit. #' @param adjust_by The maximum number of samples that one should adjust by. #' #' @return A data frame with a new column with an adjusted sample number. @@ -17,15 +17,28 @@ #' @export #' -adjust_sample_number <- function(data, budget, col_estimated, col_adjusted = "justert_ant_prover", adjust_by) { +adjust_sample_number <- function(data, budget, sample_to_adjust, adjusted_sample = "justert_ant_prover", adjust_by) { - # Justerer prøvetallet opp eller ned - total_estimated <- sum(data[, col_estimated], na.rm = TRUE) + # ARGUMENT CHECKING ---- + # Object to store check-results + checks <- checkmate::makeAssertCollection() + # Perform assertions + checkmate::assert_data_frame(x = data, all.missing = FALSE, add = checks) + checkmate::assert_integerish(budget, lower = 1, len = 1, any.missing = FALSE, add = checks) + checkmate::assert_character(sample_to_adjust, len = 1, min.chars = 1, any.missing = FALSE, add = checks) + checkmate::assert_character(adjusted_sample, len = 1, min.chars = 1, any.missing = FALSE, add = checks) + checkmate::assert_integerish(adjust_by, lower = 1, len = 1, any.missing = FALSE, add = checks) + # Report errors + checkmate::reportAssertions(checks) + + # INITILIZE VARIABLES ---- + total_estimated <- sum(data[, sample_to_adjust], na.rm = TRUE) difference <- c(as.numeric(total_estimated - budget) ,rep(NA, dim(data)[1] - 1)) + # ADJUST SAMPLE NUMBER ---- # Order data with largest sample size first - data <- data[order(data[, col_estimated], decreasing = TRUE), ] + data <- data[order(data[, sample_to_adjust], decreasing = TRUE), ] # Only justify sample number when there is disagreement between budget and calculated number of samples if (total_estimated != budget) { @@ -44,12 +57,13 @@ adjust_sample_number <- function(data, budget, col_estimated, col_adjusted = "ju if (difference[i] == 0) {justify <- 0} # Make new column with - data[i, col_adjusted] <- data[i, col_estimated] + justify + data[i, adjusted_sample] <- data[i, sample_to_adjust] + justify if (i < dim(data)[1]) { difference[i+1] <- difference[i] + justify } } } + # RETURN RESULT ---- return(data) } diff --git a/man/adjust_sample_number.Rd b/man/adjust_sample_number.Rd index 6d76596..721dd86 100644 --- a/man/adjust_sample_number.Rd +++ b/man/adjust_sample_number.Rd @@ -7,8 +7,8 @@ adjust_sample_number( data, budget, - col_estimated, - col_adjusted = "justert_ant_prover", + sample_to_adjust, + adjusted_sample = "justert_ant_prover", adjust_by ) } @@ -17,9 +17,9 @@ adjust_sample_number( \item{budget}{The total budgeted sample number.} -\item{col_estimated}{The name of the column with the sample size per unit that should be adjusted.} +\item{sample_to_adjust}{The name of the column with the sample number per unit that should be adjusted.} -\item{col_adjusted}{The name of the column with the adjusted sample size per unit.} +\item{adjusted_sample}{The name of the column with the adjusted sample number per unit.} \item{adjust_by}{The maximum number of samples that one should adjust by.} } @@ -29,7 +29,7 @@ A data frame with a new column with an adjusted sample number. \description{ Adds new column with an adjusted the sample size per selected unit. The total sample size is adjusted to be in accord with the total - budgetted sample size. + budgeted sample size. } \details{ The sample size should first be estimated by percentage or similar. From 46084d250e1d11b736f5f52038680bfc30ffd36d Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 15:10:55 +0100 Subject: [PATCH 08/28] refactor: updated contr_OK_selection Included package name when needed. Styled help. --- R/control_OK_selection.R | 58 ++++++++++++++++++++----------------- man/control_OK_selection.Rd | 6 +++- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/R/control_OK_selection.R b/R/control_OK_selection.R index 004da51..aa70617 100644 --- a/R/control_OK_selection.R +++ b/R/control_OK_selection.R @@ -19,7 +19,11 @@ #' # Control OK selection data #' #' # Read example data -#' okplan_MRSA <- read.csv2(file = paste0(set_dir_NVI("OKprogrammer"), "Rutine", plan_aar, "/planlegging/resultater/utvalgslister/data_MRSA_alle_gris.csv"), +#' okplan_MRSA <- read.csv2(file = paste0( +#' set_dir_NVI("OKprogrammer"), +#' "Rutine", +#' plan_aar, +#' "/planlegging/resultater/utvalgslister/data_MRSA_alle_gris.csv"), #' colClasses = colclasses, #' fileEncoding = "UTF-8") #' @@ -31,13 +35,13 @@ #' control_OK_selection <- function(data) { - # Antall besetninger og prøver som skal testes fordelt på grupper - print(ftable(data[, c("ok_hensiktkode", "kategori", "statuskode")], exclude = NULL)) + # Number of herds and samples that should be tested distributed on groups + print(stats::ftable(data[, c("ok_hensiktkode", "kategori", "statuskode")], exclude = NULL)) - print("Totalt antall besetninger og prøver som skal testes") + print("Totalt antall besetninger og prover som skal testes") ktr <- data %>% poorman::group_by(ok_artkode, statuskode) %>% - poorman::summarise(antall = n(), ant_prover = sum(ant_prover, na.rm = TRUE), .groups = "keep") %>% + poorman::summarise(antall = poorman::n(), ant_prover = sum(ant_prover, na.rm = TRUE), .groups = "keep") %>% poorman::ungroup() print(ktr) @@ -57,30 +61,30 @@ control_OK_selection <- function(data) { # variabelfrekvenser - print(ftable(data[, c("ok_hensiktkode", "statuskode", "kategori")], exclude = NULL)) + print(stats::ftable(data[, c("ok_hensiktkode", "statuskode", "kategori")], exclude = NULL)) - print(ftable(data[, c("ok_programkode", "analyttkode")], exclude = NULL)) - print(ftable(data[, c("mt_region")], exclude = NULL)) - print(ftable(data[, c("mt_avdeling")], exclude = NULL)) - print(ftable(data[, c("ok_aar")], exclude = NULL)) - print(ftable(data[, c("ok_programkode")], exclude = NULL)) - print(ftable(data[, c("ok_hensiktkode")], exclude = NULL)) - print(ftable(data[, c("eier_lokalitettype")], exclude = NULL)) - print(ftable(data[, c("analyttkode")], exclude = NULL)) - print(ftable(data[, c("annen_aktortype")], exclude = NULL)) - print(ftable(data[, c("annen_aktornr")], exclude = NULL)) - print(ftable(data[, c("annen_aktor")], exclude = NULL)) - print(ftable(data[, c("ant_prover", "statuskode")], exclude = NULL)) - print(ftable(data[, c("ok_artkode")], exclude = NULL)) - print(ftable(data[, c("ok_driftsformkode")], exclude = NULL)) - print(ftable(data[, c("storrelseskategori", "statuskode")], exclude = NULL)) - print(ftable(data[, c("kategori", "statuskode")], exclude = NULL)) - print(ftable(data[, c("materialekode", "statuskode")], exclude = NULL)) - print(ftable(data[, c("statuskode")], exclude = NULL)) - print(ftable(data[, c("status_dato")], exclude = NULL)) - print(ftable(data[, c("prioritet_av_reserve")], exclude = NULL)) - print(ftable(data[, c("utvalg_laget_dato")], exclude = NULL)) + print(stats::ftable(data[, c("ok_programkode", "analyttkode")], exclude = NULL)) + print(stats::ftable(data[, c("mt_region")], exclude = NULL)) + print(stats::ftable(data[, c("mt_avdeling")], exclude = NULL)) + print(stats::ftable(data[, c("ok_aar")], exclude = NULL)) + print(stats::ftable(data[, c("ok_programkode")], exclude = NULL)) + print(stats::ftable(data[, c("ok_hensiktkode")], exclude = NULL)) + print(stats::ftable(data[, c("eier_lokalitettype")], exclude = NULL)) + print(stats::ftable(data[, c("analyttkode")], exclude = NULL)) + print(stats::ftable(data[, c("annen_aktortype")], exclude = NULL)) + print(stats::ftable(data[, c("annen_aktornr")], exclude = NULL)) + print(stats::ftable(data[, c("annen_aktor")], exclude = NULL)) + print(stats::ftable(data[, c("ant_prover", "statuskode")], exclude = NULL)) + print(stats::ftable(data[, c("ok_artkode")], exclude = NULL)) + print(stats::ftable(data[, c("ok_driftsformkode")], exclude = NULL)) + print(stats::ftable(data[, c("storrelseskategori", "statuskode")], exclude = NULL)) + print(stats::ftable(data[, c("kategori", "statuskode")], exclude = NULL)) + print(stats::ftable(data[, c("materialekode", "statuskode")], exclude = NULL)) + print(stats::ftable(data[, c("statuskode")], exclude = NULL)) + print(stats::ftable(data[, c("status_dato")], exclude = NULL)) + print(stats::ftable(data[, c("prioritet_av_reserve")], exclude = NULL)) + print(stats::ftable(data[, c("utvalg_laget_dato")], exclude = NULL)) # &oMTreg*&ostatus &oMTavd*&ostatus diff --git a/man/control_OK_selection.Rd b/man/control_OK_selection.Rd index bae164b..3a76807 100644 --- a/man/control_OK_selection.Rd +++ b/man/control_OK_selection.Rd @@ -28,7 +28,11 @@ Under development. This should be rewritten to produce nicer output. # Control OK selection data # Read example data -okplan_MRSA <- read.csv2(file = paste0(set_dir_NVI("OKprogrammer"), "Rutine", plan_aar, "/planlegging/resultater/utvalgslister/data_MRSA_alle_gris.csv"), +okplan_MRSA <- read.csv2(file = paste0( + set_dir_NVI("OKprogrammer"), + "Rutine", + plan_aar, + "/planlegging/resultater/utvalgslister/data_MRSA_alle_gris.csv"), colClasses = colclasses, fileEncoding = "UTF-8") From c143fd48aae91e47a0aa6238044a840821eba3ad Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 15:11:41 +0100 Subject: [PATCH 09/28] chore: added inst/doc to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b7f403a..6d6372a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .Ruserdata *.Rproj *.Rcheck +inst/doc From 44bd5fcfca8e0cf133e78b0d2dd49bf527960258 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 15:12:22 +0100 Subject: [PATCH 10/28] chore: Added README and CONTRIBUTING to .Rbuildignore --- .Rbuildignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index 20ebdd9..8bbfc42 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,7 +6,9 @@ ^build.R ^install.R ^style.R -^README.md +^README\.md +^README\.Rmd ^doc$ ^Meta$ ^OKplan.Rcheck\vign_test$ +^CONTRIBUTING\.md From 4c2f4d7a79faa9e04a66de6db17fd06881128299 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 15:12:55 +0100 Subject: [PATCH 11/28] doc: Included README.Rmd based on template --- README.Rmd | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 README.Rmd diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..85be315 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,71 @@ +--- +title: "README" +output: + md_document: + variant: markdown_github + +params: + NVIpkg: "OKplan" +--- + +```{r, include = FALSE} +NVIpkg <- params$NVIpkg +# NVIpkg <- stringi::stri_extract_last_words(usethis::proj_path()) +NVIpkg_inline <- paste0("`", NVIpkg, "`") + +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +`r paste0(NVIpkg, ": ", desc::desc_get_field(key = "Title"))` +================ + + + + - [Overview](#overview) + - [Installation](#installation) + - [Usage](#usage) + - [Copyright and license](#copyright-and-license) + - [Contributing](#contributing) + +## Overview +```{r, include = FALSE} +description <- desc::desc_get_field(key = "Description") +``` +`r paste0(NVIpkg_inline, + "", + sub(substr(description,1,1), tolower(substr(description,1,1)), description))` + +```{r child=system.file('templates', "README_NVIverse.Rmd", package = "NVIpackager")} +``` + +## Installation +```{r child=system.file('templates', "README_installation.Rmd", package = "NVIpackager")} +``` + +## Usage +```{r child=system.file('templates', "README_usage_attach.Rmd", package = "NVIpackager")} +``` + +`r paste0(NVIpkg_inline, + "", + sub(substr(description,1,1), tolower(substr(description,1,1)), description))` + +```{r child=system.file('templates', "README_usage_help.Rmd", package = "NVIpackager")} +``` + +## Copyright and license +```{r child=system.file('templates', "README_copyright_and_license.Rmd", package = "NVIpackager")} +``` + +## Contributing +```{r child=system.file('templates', "README_contributing.Rmd", package = "NVIpackager")} +``` + + +----- +```{r child=system.file('templates', "README_code_of_conduct.Rmd", package = "NVIpackager")} +``` + From 971af5297f64e40ad49cf3d1b9f996919f39126a Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 15:15:55 +0100 Subject: [PATCH 12/28] chore: NEWS updated with changes --- NEWS | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 2d599f8..fd598b2 100644 --- a/NEWS +++ b/NEWS @@ -1,13 +1,21 @@ -OKplan 0.2.1 - (2021-04-##) +OKplan 0.2.0.9000 - (2021-11-##) -------------------------- +New features: + +- adjust_sample_number adjusts the sample numbers per unit up or down to reach the total sample size in accord with the budget. + + Bug fixes: - Included reference to NVIdb at GitHub to correct potential problems when installing the package. + Other changes: - - Updated licence to BSD-3 and copyright Holder to Norwegian Veterinary Institute. + - Updated licence to BSD_3_clause and the copyright holder to Norwegian Veterinary Institute. + + - Updated documentation and help. OKplan 0.2.0 - (2021-01-29) From 2527114f2d42c397eb86c65f3c8c6817c7e270fb Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 15:18:22 +0100 Subject: [PATCH 13/28] chore: updated DESCRIPTION Development package version. Modified description. Correcting and tyding package dependencies. --- DESCRIPTION | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 08207f3..98c41e1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: OKplan Title: Tools facilitating the planning of surveillance programmes for the NFSA -Version: 0.2.1 -Date: 2021-04-## +Version: 0.2.0.9000 +Date: 2021-11-## Authors@R: c(person(given = "Petter", family = "Hopp", @@ -9,7 +9,7 @@ Authors@R: email = "Petter.Hopp@vetinst.no"), person(given = "Norwegian Veterinary Institute", role = "cph")) -Description: The R-package include tools facilitating the planning of surveillance programmes +Description: Provide tools to facilitate the planning of surveillance programmes for the Norwegian Food Safety Authority. The package is under development. Included will be tools for: 1) Making the target population, @@ -22,20 +22,24 @@ License: BSD_3_clause + file LICENSE Encoding: UTF-8 LazyData: true Imports: + checkmate, poorman, - NVIdb (>= 0.3.0), - checkmate + stats, + NVIdb (>= 0.3.0) RoxygenNote: 7.1.1 Suggests: - usethis, + covr, + devtools, + knitr, remotes, - testthat, + rmarkdown, roxygen2, - withr, - devtools, styler, - knitr, - rmarkdown -Remotes: NorwegianVeterinaryInstitute/NVIdb + testthat, + usethis, + NVIpackager +Remotes: + NorwegianVeterinaryInstitute/NVIdb, + NorwegianVeterinaryInstitute/NVIpackager VignetteBuilder: knitr Language: en-GB From 81ebcd69ceff3f441b004e51a077cfd77e94b1ac Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Wed, 24 Nov 2021 16:27:05 +0100 Subject: [PATCH 14/28] chore: updated DESCRIPTION Changed title --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 98c41e1..b847e9e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: OKplan -Title: Tools facilitating the planning of surveillance programmes for the NFSA +Title: Tools to facilitate the Planning of Surveillance Programmes for the NFSA Version: 0.2.0.9000 Date: 2021-11-## Authors@R: From 9e4d9a3b77d582e840275a05da23694ff1ab06c8 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Thu, 25 Nov 2021 08:22:31 +0100 Subject: [PATCH 15/28] fix: renamed to adjust_samples_to_budget Can now adjust by more than 1 below adjust_by if needed. --- NAMESPACE | 2 +- ..._sample_number.R => adjust_samples_to_budget.R} | 14 ++++++++------ ...ample_number.Rd => adjust_samples_to_budget.Rd} | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) rename R/{adjust_sample_number.R => adjust_samples_to_budget.R} (82%) rename man/{adjust_sample_number.Rd => adjust_samples_to_budget.Rd} (91%) diff --git a/NAMESPACE b/NAMESPACE index c4b8216..42a5f09 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(adjust_sample_number) +export(adjust_samples_to_budget) export(control_OK_selection) export(include_generated_date) export(make_random) diff --git a/R/adjust_sample_number.R b/R/adjust_samples_to_budget.R similarity index 82% rename from R/adjust_sample_number.R rename to R/adjust_samples_to_budget.R index 8244f12..9d90600 100644 --- a/R/adjust_sample_number.R +++ b/R/adjust_samples_to_budget.R @@ -17,7 +17,7 @@ #' @export #' -adjust_sample_number <- function(data, budget, sample_to_adjust, adjusted_sample = "justert_ant_prover", adjust_by) { +adjust_samples_to_budget <- function(data, budget, sample_to_adjust, adjusted_sample = "justert_ant_prover", adjust_by) { # ARGUMENT CHECKING ---- # Object to store check-results @@ -25,7 +25,7 @@ adjust_sample_number <- function(data, budget, sample_to_adjust, adjusted_sample # Perform assertions checkmate::assert_data_frame(x = data, all.missing = FALSE, add = checks) checkmate::assert_integerish(budget, lower = 1, len = 1, any.missing = FALSE, add = checks) - checkmate::assert_character(sample_to_adjust, len = 1, min.chars = 1, any.missing = FALSE, add = checks) + checkmate::assert_choice(sample_to_adjust, choices = colnames(data), add = checks) checkmate::assert_character(adjusted_sample, len = 1, min.chars = 1, any.missing = FALSE, add = checks) checkmate::assert_integerish(adjust_by, lower = 1, len = 1, any.missing = FALSE, add = checks) # Report errors @@ -33,7 +33,7 @@ adjust_sample_number <- function(data, budget, sample_to_adjust, adjusted_sample # INITILIZE VARIABLES ---- total_estimated <- sum(data[, sample_to_adjust], na.rm = TRUE) - + n_units <- length(data[which(data[, sample_to_adjust] > 0), sample_to_adjust]) difference <- c(as.numeric(total_estimated - budget) ,rep(NA, dim(data)[1] - 1)) # ADJUST SAMPLE NUMBER ---- @@ -49,14 +49,16 @@ adjust_sample_number <- function(data, budget, sample_to_adjust, adjusted_sample # If the difference is larger than adjust_by, then adjust by adjust_by # Else adjust by 1 | -1 # If no difference "adjust by" 0 - if (abs(difference[i]) > adjust_by) { + if (abs(difference[i]) >= adjust_by) { justify <- ifelse(difference[i] > 0, -adjust_by, adjust_by) } else { - justify <- ifelse(difference[i] > 0, -1, 1) + justify <- ifelse(difference[i] > 0, + floor(- difference[i] / (n_units - i)), + ceiling(- difference[i] / (n_units - i))) } if (difference[i] == 0) {justify <- 0} - # Make new column with + # Make new column with adjusted number data[i, adjusted_sample] <- data[i, sample_to_adjust] + justify if (i < dim(data)[1]) { difference[i+1] <- difference[i] + justify diff --git a/man/adjust_sample_number.Rd b/man/adjust_samples_to_budget.Rd similarity index 91% rename from man/adjust_sample_number.Rd rename to man/adjust_samples_to_budget.Rd index 721dd86..8ebf263 100644 --- a/man/adjust_sample_number.Rd +++ b/man/adjust_samples_to_budget.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/adjust_sample_number.R -\name{adjust_sample_number} -\alias{adjust_sample_number} +\name{adjust_samples_to_budget} +\alias{adjust_samples_to_budget} \title{Adjust the sample size per selected unit} \usage{ -adjust_sample_number( +adjust_samples_to_budget( data, budget, sample_to_adjust, From efddc1541e1ab7dd46483f6bf80fad338ccc13fb Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Thu, 25 Nov 2021 08:23:13 +0100 Subject: [PATCH 16/28] test: created test_adjust_samples_to_budget --- .../testthat/test_adjust_samples_to_budget.R | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/testthat/test_adjust_samples_to_budget.R diff --git a/tests/testthat/test_adjust_samples_to_budget.R b/tests/testthat/test_adjust_samples_to_budget.R new file mode 100644 index 0000000..a98d37b --- /dev/null +++ b/tests/testthat/test_adjust_samples_to_budget.R @@ -0,0 +1,104 @@ +library(OKplan) +library(testthat) + +test_that("Adjusting sample number", { + + total_budget <- 150 + # Add data frame with sample number to adjust + x <- as.data.frame(cbind(c(1:10), + c(24, 30, 36, 12, 6, 18, 6, 0, 0, 0))) + colnames(x) <- c("id", "sample") + + x2 <- adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 6) + expect_identical(x2$new_sample, + c(42, 36, 30, 18, 12, 6, 6, 0, 0, 0)) + + x2 <- adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 4) + expect_identical(x2$new_sample, + c(40, 34, 28, 22, 13, 7, 6, 0, 0, 0)) + + x2 <- adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 10) + expect_identical(x2$new_sample, + c(46, 32, 26, 20, 13, 7, 6, 0, 0, 0)) + + total_budget <- 130 + + x2 <- adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 6) + expect_identical(x2$new_sample, + c(35, 29, 24, 18, 12, 6, 6, 0, 0, 0)) + + x2 <- adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 2) + expect_identical(x2$new_sample, + c(34, 30, 24, 18, 12, 6, 6, 0, 0, 0)) +}) + + +test_that("Errors for adjust_sample_number", { + + total_budget <- 150 + # Add data frame with sample number to adjust + x <- as.data.frame(cbind(c(1:10), + c(24, 30, 36, 12, 6, 18, 6, 0, 0, 0))) + colnames(x) <- c("id", "sample") + + expect_error( + adjust_samples_to_budget(data = total_budget, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 6), + regexpr = "Variable \'data\': Must be of type \'data.frame\'") + + expect_error( + adjust_samples_to_budget(data = x, + budget = 0, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 6), + regexpr = "Variable \'budget\': Element 1 is not >= 1") + + expect_error( + adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "samples", + adjusted_sample = "new_sample", + adjust_by = 6), + regexpr = "Variable \'sample_to_adjust\': Must be element of set {\'id\',\'sample\'}, but is \'samples\'") + + expect_error( + adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = total_budget, + adjust_by = 6), + regexpr = "Variable \'adjusted_sample\': Must be of type \'character\', not \'double\'") + + expect_error( + adjust_samples_to_budget(data = x, + budget = total_budget, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 0), + regexpr = "Variable \'adjust_by\': Element 1 is not >= 1") + +}) From 989108e93c7248e33f584bdcf829b7ded91a78d0 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Thu, 25 Nov 2021 08:36:16 +0100 Subject: [PATCH 17/28] doc: included example in adjust_samples_to_budget --- R/adjust_samples_to_budget.R | 12 ++++++++++++ man/adjust_samples_to_budget.Rd | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/R/adjust_samples_to_budget.R b/R/adjust_samples_to_budget.R index 9d90600..a144e8b 100644 --- a/R/adjust_samples_to_budget.R +++ b/R/adjust_samples_to_budget.R @@ -15,6 +15,18 @@ #' #' @author Petter Hopp Petter.Hopp@@vetinst.no #' @export +#' @examples +#' # Add data frame with sample number to adjust +#' x <- as.data.frame(cbind(c(1:10), +#' c(24, 30, 36, 12, 6, 18, 6, 0, 0, 0))) +#' colnames(x) <- c("id", "sample") +#' +#' # Adjust total sample number to budget +#' x <- adjust_samples_to_budget(data = x, +#' budget = 150, +#' sample_to_adjust = "sample", +#' adjusted_sample = "new_sample", +#' adjust_by = 4) #' adjust_samples_to_budget <- function(data, budget, sample_to_adjust, adjusted_sample = "justert_ant_prover", adjust_by) { diff --git a/man/adjust_samples_to_budget.Rd b/man/adjust_samples_to_budget.Rd index 8ebf263..0234a87 100644 --- a/man/adjust_samples_to_budget.Rd +++ b/man/adjust_samples_to_budget.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/adjust_sample_number.R +% Please edit documentation in R/adjust_samples_to_budget.R \name{adjust_samples_to_budget} \alias{adjust_samples_to_budget} \title{Adjust the sample size per selected unit} @@ -33,6 +33,20 @@ Adds new column with an adjusted the sample size per selected } \details{ The sample size should first be estimated by percentage or similar. +} +\examples{ +# Add data frame with sample number to adjust +x <- as.data.frame(cbind(c(1:10), + c(24, 30, 36, 12, 6, 18, 6, 0, 0, 0))) +colnames(x) <- c("id", "sample") + +# Adjust total sample number to budget +x <- adjust_samples_to_budget(data = x, + budget = 150, + sample_to_adjust = "sample", + adjusted_sample = "new_sample", + adjust_by = 4) + } \author{ Petter Hopp Petter.Hopp@vetinst.no From 65f793fbf88b12e0ac434888bf4330a2c75741a0 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Thu, 25 Nov 2021 10:55:24 +0100 Subject: [PATCH 18/28] refactor: renamed to check_OK_selection --- NAMESPACE | 2 +- ...ntrol_OK_selection.R => check_OK_selection.R} | 10 +++++----- ...rol_OK_selection.Rd => check_OK_selection.Rd} | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) rename R/{control_OK_selection.R => check_OK_selection.R} (94%) rename man/{control_OK_selection.Rd => check_OK_selection.Rd} (79%) diff --git a/NAMESPACE b/NAMESPACE index 42a5f09..969df94 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand export(adjust_samples_to_budget) -export(control_OK_selection) +export(check_OK_selection) export(include_generated_date) export(make_random) diff --git a/R/control_OK_selection.R b/R/check_OK_selection.R similarity index 94% rename from R/control_OK_selection.R rename to R/check_OK_selection.R index aa70617..f7e3dac 100644 --- a/R/control_OK_selection.R +++ b/R/check_OK_selection.R @@ -16,7 +16,7 @@ #' @export #' @examples #' \dontrun{ -#' # Control OK selection data +#' # Checking OK selection data #' #' # Read example data #' okplan_MRSA <- read.csv2(file = paste0( @@ -24,16 +24,16 @@ #' "Rutine", #' plan_aar, #' "/planlegging/resultater/utvalgslister/data_MRSA_alle_gris.csv"), -#' colClasses = colclasses, -#' fileEncoding = "UTF-8") +#' colClasses = colclasses, +#' fileEncoding = "UTF-8") #' #' # Control -#' control_OK_selection(okplan_MRSA) +#' check_OK_selection(okplan_MRSA) #' #' } #' #' -control_OK_selection <- function(data) { +check_OK_selection <- function(data) { # Number of herds and samples that should be tested distributed on groups print(stats::ftable(data[, c("ok_hensiktkode", "kategori", "statuskode")], exclude = NULL)) diff --git a/man/control_OK_selection.Rd b/man/check_OK_selection.Rd similarity index 79% rename from man/control_OK_selection.Rd rename to man/check_OK_selection.Rd index 3a76807..5afe0a8 100644 --- a/man/control_OK_selection.Rd +++ b/man/check_OK_selection.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/control_OK_selection.R -\name{control_OK_selection} -\alias{control_OK_selection} +% Please edit documentation in R/check_OK_selection.R +\name{check_OK_selection} +\alias{check_OK_selection} \title{Control of standard output file with OK selection} \usage{ -control_OK_selection(data) +check_OK_selection(data) } \arguments{ \item{data}{Data frame with selection for a OK programme.} @@ -25,7 +25,7 @@ Under development. This should be rewritten to produce nicer output. } \examples{ \dontrun{ -# Control OK selection data +# Checking OK selection data # Read example data okplan_MRSA <- read.csv2(file = paste0( @@ -33,11 +33,11 @@ okplan_MRSA <- read.csv2(file = paste0( "Rutine", plan_aar, "/planlegging/resultater/utvalgslister/data_MRSA_alle_gris.csv"), - colClasses = colclasses, - fileEncoding = "UTF-8") + colClasses = colclasses, + fileEncoding = "UTF-8") # Control -control_OK_selection(okplan_MRSA) +check_OK_selection(okplan_MRSA) } From 59cbe6fe4bcfc71739970aa2b468de45ee80df29 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Thu, 25 Nov 2021 10:57:01 +0100 Subject: [PATCH 19/28] fix: corrected calculating n_units in adjust_samples_to_budget --- R/adjust_samples_to_budget.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/adjust_samples_to_budget.R b/R/adjust_samples_to_budget.R index a144e8b..2a937bd 100644 --- a/R/adjust_samples_to_budget.R +++ b/R/adjust_samples_to_budget.R @@ -45,7 +45,7 @@ adjust_samples_to_budget <- function(data, budget, sample_to_adjust, adjusted_sa # INITILIZE VARIABLES ---- total_estimated <- sum(data[, sample_to_adjust], na.rm = TRUE) - n_units <- length(data[which(data[, sample_to_adjust] > 0), sample_to_adjust]) + n_units <- length(which(data[, sample_to_adjust] > 0)) difference <- c(as.numeric(total_estimated - budget) ,rep(NA, dim(data)[1] - 1)) # ADJUST SAMPLE NUMBER ---- From 83f66ff176a6b109e164a6631c2e29f5fe7bed13 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Fri, 26 Nov 2021 10:44:55 +0100 Subject: [PATCH 20/28] feat: created append_sum_line --- NAMESPACE | 3 ++- R/append_sum_line.R | 53 ++++++++++++++++++++++++++++++++++++++++++ man/append_sum_line.Rd | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 R/append_sum_line.R create mode 100644 man/append_sum_line.Rd diff --git a/NAMESPACE b/NAMESPACE index 969df94..5082727 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(adjust_samples_to_budget) +export(append_date_generated_line) +export(append_sum_line) export(check_OK_selection) -export(include_generated_date) export(make_random) diff --git a/R/append_sum_line.R b/R/append_sum_line.R new file mode 100644 index 0000000..dd165a2 --- /dev/null +++ b/R/append_sum_line.R @@ -0,0 +1,53 @@ +#' @title Append row with column sums +#' @description Appends a new row with column sums for selected columns. A pretext can be placed on the row. +#' +#' @details One row is appended to the data frame. The sum is calculated with na.rm = TRUE. +#' +#' If a tibble, it is transformed to a data frame to avoid errors if the pretext is to be placed in a numeric variable. +#' +#' @param data Data frame to which a row should be appended. +#' @param column Character vector. The column names of columns to sum. +#' @param pretext The explaining text before the sum, defaults to "Sum". +#' @param position The position for the pretext, on of c("first", left", "none"). defaults to left. +#' +#' @return A data frame with an appended row with sums. +#' +#' @author Petter Hopp Petter.Hopp@@vetinst.no +#' @export +#' @examples +#' \dontrun{ +#' # Append row with sum +#' gris_blodprover_slakteri <- append_sum_line(data = gris_blodprover_slakteri, +#' col_name = c("ant_prover"), +#' pretext = "Sum", +#' position = "first") +#' } +#' + + +append_sum_line <- function(data, column, pretext = "Sum", position = "left") { + + # Removes tibble as tibble will not accept the the pretext (character variable) in a numeric variable + data <- as.data.frame(data) + + # Sum for one or more columns + if (length(column) == 1) { + sum_column <- unname(sum(data[, column], na.rm = TRUE)) + } else { + sum_column <- unname(colSums(data[, column], na.rm = TRUE)) + } + + # Append a line with the sum. The pretext is placed in accord with position + if (position == "none") { + data[dim(data)[1] + 1, c(column)] <- c(sum_column) + } + if (position == "first") { + data[dim(data)[1] + 1, c(colnames(data)[1], column)] <- c(pretext, sum_column) + } + if (position == "left") { + data[dim(data)[1] + 1, c((colnames(data)[which(colnames(data) == column[1]) - 1]), column)] <- c(pretext, sum_column) + } + + # RETURN RESULTS ---- + return(data) +} diff --git a/man/append_sum_line.Rd b/man/append_sum_line.Rd new file mode 100644 index 0000000..a7af178 --- /dev/null +++ b/man/append_sum_line.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/append_sum_line.R +\name{append_sum_line} +\alias{append_sum_line} +\title{Append row with column sums} +\usage{ +append_sum_line(data, column, pretext = "Sum", position = "left") +} +\arguments{ +\item{data}{Data frame to which a row should be appended.} + +\item{column}{Character vector. The column names of columns to sum.} + +\item{pretext}{The explaining text before the sum, defaults to "Sum".} + +\item{position}{The position for the pretext, on of c("first", left", "none"). defaults to left.} +} +\value{ +A data frame with an appended row with sums. +} +\description{ +Appends a new row with column sums for selected columns. A pretext can be placed on the row. +} +\details{ +One row is appended to the data frame. The sum is calculated with na.rm = TRUE. + + If a tibble, it is transformed to a data frame to avoid errors if the pretext is to be placed in a numeric variable. +} +\examples{ +\dontrun{ +# Append row with sum +gris_blodprover_slakteri <- append_sum_line(data = gris_blodprover_slakteri, + col_name = c("ant_prover"), + pretext = "Sum", + position = "first") +} + +} +\author{ +Petter Hopp Petter.Hopp@vetinst.no +} From 6835047f9ee01a4501acabea5b8465b260a2f94f Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Fri, 26 Nov 2021 10:45:53 +0100 Subject: [PATCH 21/28] refactor: renamed to append_date_generated_line --- ...e_generated_date.R => append_date_generated_line.R} | 4 ++-- ...generated_date.Rd => append_date_generated_line.Rd} | 10 +++++----- ...erated_date.R => test_append_date_generated_line.R} | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) rename R/{include_generated_date.R => append_date_generated_line.R} (86%) rename man/{include_generated_date.Rd => append_date_generated_line.Rd} (77%) rename tests/testthat/{test_include_generated_date.R => test_append_date_generated_line.R} (80%) diff --git a/R/include_generated_date.R b/R/append_date_generated_line.R similarity index 86% rename from R/include_generated_date.R rename to R/append_date_generated_line.R index df96b5f..6937cd1 100644 --- a/R/include_generated_date.R +++ b/R/append_date_generated_line.R @@ -14,11 +14,11 @@ #' @examples #' \dontrun{ #' # Add row with generated date using standard values -#' gris_virus_slaktegris_utvalg <- include_generated_date(gris_virus_slaktegris_utvalg) +#' gris_virus_slaktegris_utvalg <- append_date_generated_line(gris_virus_slaktegris_utvalg) #' #' } #' -include_generated_date <- function(data, pretext = "Datauttrekket er gjort", date = format(Sys.Date(),"%d/%m/%Y")) { +append_date_generated_line <- function(data, pretext = "Datauttrekket er gjort", date = format(Sys.Date(),"%d/%m/%Y")) { # Argument checking checks <- checkmate::makeAssertCollection() diff --git a/man/include_generated_date.Rd b/man/append_date_generated_line.Rd similarity index 77% rename from man/include_generated_date.Rd rename to man/append_date_generated_line.Rd index edffbd0..64bd8e8 100644 --- a/man/include_generated_date.Rd +++ b/man/append_date_generated_line.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/include_generated_date.R -\name{include_generated_date} -\alias{include_generated_date} +% Please edit documentation in R/append_date_generated_line.R +\name{append_date_generated_line} +\alias{append_date_generated_line} \title{Add new last row with generated date} \usage{ -include_generated_date( +append_date_generated_line( data, pretext = "Datauttrekket er gjort", date = format(Sys.Date(), "\%d/\%m/\%Y") @@ -29,7 +29,7 @@ Two rows are dded to the data frame, the first is empty, the second has the gene \examples{ \dontrun{ # Add row with generated date using standard values -gris_virus_slaktegris_utvalg <- include_generated_date(gris_virus_slaktegris_utvalg) +gris_virus_slaktegris_utvalg <- append_date_generated_line(gris_virus_slaktegris_utvalg) } diff --git a/tests/testthat/test_include_generated_date.R b/tests/testthat/test_append_date_generated_line.R similarity index 80% rename from tests/testthat/test_include_generated_date.R rename to tests/testthat/test_append_date_generated_line.R index 8b6b315..26524c7 100644 --- a/tests/testthat/test_include_generated_date.R +++ b/tests/testthat/test_append_date_generated_line.R @@ -1,8 +1,7 @@ -context("include_generated_date") library(OKplan) library(testthat) -test_that("Including generated date in last row", { +test_that("Append date generated in last row", { # Make example data @@ -11,7 +10,7 @@ x <- as.data.frame(cbind("År" = 2021, "Rapport" = "Brucellose hos geit, utvalgs "Produsentnr" = "30303030", "Foretak" = "XXX XXXXX", "Postnr" = "0468", "Poststed" = "OSLO", "Antall prøver" = 26)) # Include row with generated date -y <- include_generated_date(x) +y <- append_date_generated_line(x) expect_equal(dim(y)[1], dim(x)[1] + 2) expect_identical(y[dim(y)[1], 1], paste("Datauttrekket er gjort", format(Sys.Date(),"%d/%m/%Y"))) @@ -19,7 +18,7 @@ expect_identical(y[dim(y)[1], 1], paste("Datauttrekket er gjort", format(Sys.Dat # Include row with generated date today <- format(Sys.Date(),"%d/%m/%Y") -y <- include_generated_date(x, pretext = "Data was generated", date = today) +y <- append_date_generated_line(x, pretext = "Data was generated", date = today) expect_equal(dim(y)[1], dim(x)[1] + 2) expect_identical(y[dim(y)[1], 1], paste("Data was generated", format(Sys.Date(),"%d/%m/%Y"))) From 5c5f38901a5ddd485e3f4c571255ac6f5ee79fc8 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Mon, 29 Nov 2021 13:32:08 +0100 Subject: [PATCH 22/28] refactor: updated OK_column_standards --- data/OK_column_standards.rda | Bin 1841 -> 1846 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/data/OK_column_standards.rda b/data/OK_column_standards.rda index b9dbb3f4f2d1099a63a2b59bac36e7b0c7e3a0bb..9e1dfc5749a5882036ff036efed122e0ba35ed19 100644 GIT binary patch literal 1846 zcmV-62g&$CT4*^jL0KkKS#N;TkN_9O|J?uo|88}6|Ns6D-C)1}-{`^s5&!@|2mn9< z;0hmoqfi2$E00x=>8Uc_101P5hnNLKX zrcE?xJwqX*A?ZC#gK7W(JwO9Nk)Y53R8a^BBOnt^Piksuk(yJ~_K_NCpaVld1Jrtt zQ)*|bY3h2PVo4+QMB{_m?8k1A_wgPm?G5O|^Gy|P6Xo-aZB9L;Sf)b1rv`kAFCWv8S2~3%w9myaO(0~8{ zpW#qLMdM3I;E14LiW-n;CHN?`6;dFM(Lhi=BtcJ+5lH|U6|_MqEf5f-Rz(>F*COPR z_d;mEEU1-WukvBC$(lyy7)nur5wM1_vyOnfF;MJQez!FssaaB4*4qvnL?d*KXKFuR z+vDPqBbAbBL+bBl2?XmERaH{HHFiEmB0nYbSqT^Y_YA35_f;5vhZa%Vcs`sMSuQb# zJh(IFvkKIgd(51;Ff{t>Q>`mQgGFn$_TjgWa!u{+6B{hD^0G;cI(B-+WcV$IB|q}+o&IYsN;drZuA7ICy%p(_X~j!!69R)s~sEIk97GH$;&h6p}<( zkRbvh37HTPOz0?~#aO6b5&|NYNfeesMN|s03Rxm5YvfT;5~YYOa8`)L1}qjrqFEhh z0pkTv0KhPsBu@%d>`tF=Y8puOzN}%6tcl)BdZl`*TNc_awJjE{lG$upg{)%|TN2Qa z8`6YH5WNDF8b(M-SepXk4A6W7Qth@X9RcJGTHveU8-sjm7svr@14u9%^CC(8MBX$X zGyBeOlj%wQgRLg?`ZNQedo%E(-+gaVPne$gSIC3;7#N89bz$S;I%^a!37R(s5X%!R9r7pYNb_`P?R4qhO-jS1jny2BEFDaOO#7r5 z8asUh6v*j|mb^q74x34_JGy`SPk& zc+Z9-gD*?rb0EY=IisLT>3h!j>nDO93?#t9**szx855Z+d-@+yy}i}Y%aeMgRU@s+ zLkLbg6VJK)JubN9O9hcdV4+}}wKGdO0<-Q_mV=$lggZ;H>71y zoG|sTh?B;mA34(e4J14cE}SfC<88Lx@hvtV*($PuzABbHd*n+BwaAjVFN>u&&nW9=EJF z2kZs|^rrKCk$Bey4s?}fkkc&LnM!12lsRhA;(Q-3dt29xV$*N2XC}bR8I&gDvb76!}PJw}9ZFF;LG^wj(msXfVOk!sBwsA)xfyipw+Z?L*X) zfYlySdmof~p2J}cWQWF&bsf@nj}(y{#^+Q{`$HCI)?|PJu4M|`Cr<}Mp$Ju7%@?a6^e?I z(N`Eq>{%sNRzzA$j7f{VBVodf#!y4h|!&6YMABVGT*6UFp`MtxKjNEzDQl2RMv7TB@qGb|YYQ z_4oVSBsLr;1ti%x6W>Is7-h*2;$U!S(uVDqn=PDOtRzFS2=H`zdlyo<@$aRcA0(5tvo|YO&Nh($ literal 1841 zcmV-12hR9HT4*^jL0KkKS-E_i9{?AY|J?uo|88}6|Ns6D-C)1}-|)i#5&!@|2mn9< z;0hj}000l2r~m)}0001pNKBd&N1#nJNs*%fnWSSQYD^}WgA)Y7G{G7)2Mqww0B8*X zpa1|GXwyI$000ddWEkO~8UPIepfmsg15Fxe10VnaqfCPg)T#gg00006KmY&$00006 zK@~{S0iXZ?H1z-jKpFr500uw+08)}5fieJ-(@h#fBTOmi)YC>l0kr@$$jOPOdXr5( zPsJ5Ik*$o&ml{e|U%-*4fU`*U!72h9kR)9)fkFZb!~+BoBNY!|EC>;VV~89;K#535 zP?Q3x0({3v%~_J7dh^_e0SAzbmu_iFlc%OUMK^|(V1W5DmHR`SAJCA8NQel}q9Q%} z>gLk;@{suQPnQ;l*vM9?QxadPq(}L(Rry&VnG-U$WScS#vRR2^75N!m%&nNS6Y*m) zHDOrFxU~EYj!dnxjAIzFgA7~X=g3n#IW3rDKI;=t(9(D>7vt5e%$~+t z+ZnB9SY@6b6y)|770t=I*BoXt%O*0*H>5GoJ zDJPIrn4nBDMDk=sJvgZzs=++t5KJTek1ZDzg%-k=ULpdR~;Ptt!GCLl>d>p9yWvGMU$z;V)vj)OS3| zacuDpm-ikST!*3mXzWtm>mBD8iQvU`vaLl~4^qP{3{BfHlChXrM<<$$rF#pePD*UV zSoq#Vc~~RfJ0AmjJY5Xz#!e30%*@Q^QRf_6j!ltuniuavw-+7%y_m)-e z!94D-S87$;CD=m(VOzBQCrYu5GOT2=mKk4lzlgZJt*%YociL@v6C4ISZZ!Cx5ONQY zG#{mNIn?XZp{)mA7Bb#8*|u9)VX)Y+I=DA^p8xK5_-A&ttizA(W*G4c*`i%fL$L7< zDOcPW8v~~Kms_RH*4d?O!u4rd87?`yslacGgNn0*eItEp+dG_HDbzGNhX)+YuA3OW zX!>g1K9YK#>*YHHZ&C0kp*_m*k0O((a(AWfHKOsZ4L;K;?uIxQ>n)Xo6WV{{!l%+x z_6xl8J8CydxrcG~oFKw9r=9)8Qvu4Y6qgYxP)+S3Z zX_`~O%CU_ylQ6SdtyIP-Xl$3#_Fn+qx|y9J+8wXF*|Qaj^D)G_Ol5`#+j(77tyu9tgBZp*JSoH- zz7AAwIb4`m1<1atStgr05 Date: Mon, 29 Nov 2021 13:46:12 +0100 Subject: [PATCH 23/28] chore: NEWS and DESCRIPTION v0.3.0 --- DESCRIPTION | 17 +++++++---------- NEWS | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b847e9e..c3e210d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: OKplan -Title: Tools to facilitate the Planning of Surveillance Programmes for the NFSA -Version: 0.2.0.9000 -Date: 2021-11-## +Title: Tools to facilitate the Planning of the annual Surveillance Programmes +Version: 0.3.0 +Date: 2021-11-29 Authors@R: c(person(given = "Petter", family = "Hopp", @@ -9,12 +9,9 @@ Authors@R: email = "Petter.Hopp@vetinst.no"), person(given = "Norwegian Veterinary Institute", role = "cph")) -Description: Provide tools to facilitate the planning of surveillance programmes - for the Norwegian Food Safety Authority. The package is under development. Included will - be tools for: - 1) Making the target population, - 2) Random selection, - 3) generate lists for the NFSA. +Description: Provide tools to facilitate the planning of the annual surveillance + programmes. The main focus is tools for generating standardized lists for + NFSA. URL: https://github.com/NorwegianVeterinaryInstitute/OKplan BugReports: https://github.com/NorwegianVeterinaryInstitute/OKplan/issues Depends: R (>= 3.5.0) @@ -26,7 +23,6 @@ Imports: poorman, stats, NVIdb (>= 0.3.0) -RoxygenNote: 7.1.1 Suggests: covr, devtools, @@ -41,5 +37,6 @@ Suggests: Remotes: NorwegianVeterinaryInstitute/NVIdb, NorwegianVeterinaryInstitute/NVIpackager +RoxygenNote: 7.1.1 VignetteBuilder: knitr Language: en-GB diff --git a/NEWS b/NEWS index fd598b2..b8b250f 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,12 @@ -OKplan 0.2.0.9000 - (2021-11-##) --------------------------- +OKplan 0.3.0 - (2021-11-29) +--------------------------- New features: - adjust_sample_number adjusts the sample numbers per unit up or down to reach the total sample size in accord with the budget. +- append_sum_line appends a line with the sum of samples to the table in Excel. + Bug fixes: @@ -18,8 +20,13 @@ Other changes: - Updated documentation and help. +BREAKING CHANGES: + + - Renamed to append_date_generated_line from include_generated_date. + + OKplan 0.2.0 - (2021-01-29) --------------------------- +--------------------------- New features: @@ -27,7 +34,7 @@ New features: OKplan 0.1.1 - (2021-01-01) --------------------------- +--------------------------- Other changes: @@ -35,7 +42,7 @@ Other changes: OKplan 0.1.0 - (2020-12-30) --------------------------- +--------------------------- First release: From 8bacd8772bf5d0039fe4fb49583ecf0f0d199381 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Mon, 29 Nov 2021 14:07:31 +0100 Subject: [PATCH 24/28] doc: updated CONTRIBUTING and Contribute_to_OKplan.Rmd from template. --- CONTRIBUTING.md | 2 +- vignettes/Contribute_to_OKplan.Rmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b11d420..96ba540 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -153,7 +153,7 @@ adhere to some principles and style convention used for Please don’t restyle code that has nothing to do with your pull request. -- You should add a bullet point to `NEWS` motivating the change. +- You should add a bullet point to `NEWS.md` motivating the change. - You should add yourself as a contributor to the `DESCRIPTION`. diff --git a/vignettes/Contribute_to_OKplan.Rmd b/vignettes/Contribute_to_OKplan.Rmd index d0199ba..e02a0e5 100644 --- a/vignettes/Contribute_to_OKplan.Rmd +++ b/vignettes/Contribute_to_OKplan.Rmd @@ -95,7 +95,7 @@ I recommend to use the [`styler`](https://CRAN.R-project.org/package=styler) package to apply spaces: `styler::style_file(filename, scope = "spaces")`. Please don't restyle code that has nothing to do with your pull request. -* You should add a bullet point to `NEWS` motivating the change. +* You should add a bullet point to `NEWS.md` motivating the change. * You should add yourself as a contributor to the `DESCRIPTION`. From 918d457a79ff8515b30b227b9d79520fbacf461a Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Mon, 29 Nov 2021 14:08:55 +0100 Subject: [PATCH 25/28] chore: updated README.md from template --- README.md | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f1c330d..f1d6ca1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,89 @@ -# OKplan -Tools facilitating the planning of surveillance programmes for the NFSA - -The R-package include tools facilitating the planning of surveillance programmes for the Norwegian Food Safety Authority. Tha package is under development. -Included will be tools for -- Making the target population -- Random selection -- generate lists for the NFSA +OKplan: Tools to facilitate the Planning of the annual Surveillance Programmes +============================================================================== + + + +- [Overview](#overview) +- [Installation](#installation) +- [Usage](#usage) +- [Copyright and license](#copyright-and-license) +- [Contributing](#contributing) + +Overview +-------- + +`OKplan`provide tools to facilitate the planning of the annual +surveillance programmes. The main focus is tools for generating +standardized lists for NFSA. + +`OKplan` is part of `NVIverse`, a collection of R-packages with tools to +facilitate data management and data reporting at the Norwegian +Veterinary Institute (NVI). The NVIverse consists of the following +packages: NVIconfig, NVIdb, NVIpretty, NVIbatch, OKplan, OKcheck, +NVIcheckmate, NVIpackager. See the vignette “Contribute to OKplan” for +more information. + +Installation +------------ + +`OKplan` is available at +[GitHub](https://github.com/NorwegianVeterinaryInstitute). To install +`OKplan` you will need: + +- R version > 4.0.0 +- R package `remotes` +- Rtools 4.0 + +First install and attach the `remotes` package. + + install.packages("remotes") + library(remotes) + +To install (or update) the `OKplan` package, run the following code: + + remotes::install_github("NorwegianVeterinaryInstitute/OKplan") + upgrade = FALSE, + build = TRUE, + build_manual = TRUE) + +Usage +----- + +The `OKplan` package needs to be attached. + + library(NVIdb) + +`OKplan`provide tools to facilitate the planning of the annual +surveillance programmes. The main focus is tools for generating +standardized lists for NFSA. + +The list of available functions and datasets can be accessed by typing + + help(package="NVIdb") + +Please check the NEWS for information on new features, bug fixes and +other changes. + +Copyright and license +--------------------- + +Copyright (c) 2021 Norwegian Veterinary Institute. +Licensed under the BSD\_3\_clause License. See +[License](https://github.com/NorwegianVeterinaryInstitute/OKplan/blob/main/LICENSE) +for details. + +Contributing +------------ + +Contributions to develop `OKplan` is highly appreciated. There are +several ways you can contribute to this project: ask a question, propose +an idea, report a bug, improve the documentation, or contribute code. +The vignette “Contribute to OKplan” gives more information. + + +------------------------ + +Please note that the OKplan project is released with a [Contributor Code +of +Conduct](https://github.com/NorwegianVeterinaryInstitute/OKplan/blob/main/CODE_OF_CONDUCT.md). +By contributing to this project, you agree to abide by its terms. From 39eb251c291f5f02db9e9de66689d7ba60a0396b Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Mon, 29 Nov 2021 14:10:10 +0100 Subject: [PATCH 26/28] refactor: used dplyr instead of poorman in generate_OK_column_standards --- data-raw/generate_OK_column_standards.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/data-raw/generate_OK_column_standards.R b/data-raw/generate_OK_column_standards.R index ea07788..ac862bd 100644 --- a/data-raw/generate_OK_column_standards.R +++ b/data-raw/generate_OK_column_standards.R @@ -20,29 +20,29 @@ library(usethis) # READS AND TRANSFORMS EXCEL SHEET WITH COLUMN STANDARD INFORMATION ---- OK_column_standards <- read.xlsx(xlsxFile = paste0(set_dir_NVI("ProgrammeringR"), "standardization/colnames/colnames_translation_table.xlsx")) %>% # Selects only information used in OK-planning - poorman::filter(db == "OK_planlegging") %>% + dplyr::filter(db == "OK_planlegging") %>% # Generates column labels based on label and spec for no and en # Use exactly same transformations as for column_standards - poorman::rename(label_no = collabel_no, label_en = collabel_en) %>% - poorman::mutate(label_1_no = poorman::case_when(is.na(spec_no) ~ label_no, + dplyr::rename(label_no = collabel_no, label_en = collabel_en) %>% + dplyr::mutate(label_1_no = dplyr::case_when(is.na(spec_no) ~ label_no, spec_no %in% c("dato", "geometrisk middel 3") ~ paste(label_no, spec_no), spec_no %in% c("kg", "kjennelse", "tid") ~ label_no, spec_no %in% c("antall undersøkt") ~ paste(spec_no, label_no), TRUE ~ spec_no)) %>% - poorman::mutate(label_1_en = poorman::case_when(is.na(spec_en) ~ label_en, + dplyr::mutate(label_1_en = dplyr::case_when(is.na(spec_en) ~ label_en, spec_en %in% c("date") ~ paste(label_en, spec_en), spec_en %in% c("kg", "time", "determination") ~ label_en, spec_en %in% c("No. tested") ~ paste(spec_en, label_en), TRUE ~ spec_en)) %>% # selects, renames and orders columns - poorman::select(db, table_db, colname_db, colname, label_1_no, label_no, spec_no, label_1_en, label_en, spec_en, + dplyr::select(db, table_db, colname_db, colname, label_1_no, label_no, spec_no, label_1_en, label_en, spec_en, colwidth_Excel = colwidth_excel, colwidth_DT = colwidth_dt_tables, colclasses, colorder) %>% - poorman::distinct() + dplyr::distinct() # Generate data frame with all table names db_tables <- as.data.frame(unique(OK_column_standards$table_db)) %>% - poorman::rename(tables = 1) %>% + dplyr::rename(tables = 1) %>% dplyr::mutate(table = strsplit(tables, split = ",")) %>% dplyr::mutate_if(is.list, purrr::simplify_all) %>% # flatten each list element internally tidyr::unnest(cols = "table")# expand @@ -59,9 +59,9 @@ db_tables <- as.data.frame(unique(OK_column_standards$table_db)) %>% # Generate table with each table name on one line OK_column_standards <- OK_column_standards %>% - poorman::left_join(db_tables, by = c("table_db" = "tables")) %>% - poorman::mutate(table_db = trimws(table)) %>% - poorman::select(!table) + dplyr::left_join(db_tables, by = c("table_db" = "tables")) %>% + dplyr::mutate(table_db = trimws(table)) %>% + dplyr::select(!table) # unique_colnames <- unique(column_standards[, c("colname_db", "colname")]) %>% # poorman::add_count(colname_db, name = "unique_colnames") %>% From 7c8ba609a9b7b36ef0c2400c28b3d4e7d0065ed2 Mon Sep 17 00:00:00 2001 From: Petter Hopp Date: Mon, 29 Nov 2021 14:10:54 +0100 Subject: [PATCH 27/28] refactor: updated OK_column_standards.rda --- data/OK_column_standards.rda | Bin 1846 -> 1836 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/data/OK_column_standards.rda b/data/OK_column_standards.rda index 9e1dfc5749a5882036ff036efed122e0ba35ed19..88e87bf14091af173581c95330470a64bdd704d4 100644 GIT binary patch delta 1788 zcmVaiO81pc(@ZGzLHb8fXA$20#D+Fo{q=jWsZyplHz3N2tWp zAbNlR007X*rh`Cwfl)+2ASRj(O*DF^qf&S^O`1q;LqG?q>SzJ#Hlt5L>W!p*$s~`} z6NV38uN|64!HDt<-)b}GJr$>T*Y7-IRu*vJC`)qIt%};=%3TzHsupHGPL@k+P;kzU zwfmg&NSXo8n6yN~fRRW!P{9dC3R)&5j1xpKu!N>e&<^B~2!!T%UAvRq>fc<^V*W)-P7Jc;>t zur>VksnnIBz2Vh`*}b%E->OZ`trHs-S$NzmAN`uFL_T}(NWZe=A=y{!L{!+wpal}8fGu!Vgkpmh3n5V~j+1!t0;h;z7)=r< zjUeTYN9Qm?r8Lc^iV81M1ClacVV?#>lF@CcXtivX%VN|mV;GXymX?#c;bPc#Qy5HH zZCk27#Ggs-2f#HhHqArF90OLsD)>g&=#4`8KrH}&d_jQSnG#RzCgGs@U*K|jzba42 zI#O;=uRuA6&7aywzwfWw_mX~sdP2QOKb?VykF!=EfujWb?jJAPqc2)G6KmGoi8bB3 zCe&{y84^v-2#;ftHj5`VtQ%~4s}d?qB9X}(tdDe`TLx=-C2Guu5NaNw_*|qX5eQ0A|4yK0|1xTmIx!M#S zm;16Ac9V4WBdCsp1iFYsN=zajs?jtAaq_R=m@a1N-4VK@dd-C9-h`fV4%`f}?js|( z?ss;XV;C$|Zp6aIDW1P!JIU-v&_>6$>Qt70s%?=Z=OD@*f$9%Ctoc zI|wlm$)x5Ix!#9Z=_iH0$>GXO3@ww!A%T%O61TpW<~O%5GPt&?RZ==!Brt^3n!l5i zqB@CUGAOJRE{T|?ah#&K>MH>PzzUvc=6qz%=vfuY-vK<5Zjv1@8YaeFgM<4|0!g%g zd7q&UWQn8LIolnMJ$Df%5hSp8r7WRQqbji_T1rD}$01}%elq*7_`~ zoj18RIWWQ}eu05vY`QqL8dTM>CDo=7(-@h(EshA{FgT4{EwRE< zW6=4Hf*Q#Wi5}WJ!dk=Xo6x zLrD@%!Qdx}@FUD0Ghse){VO{YZ@)|Y`qaGW|@=b|3L|Bo|;7pBMeb;)sS~YJvqI*>)Ce)$l z9w#{KbSB<`@;vScZ*Uz*pK(7E2x?6l?oO2zYF#lAZeqRQa)`sRs;aAhSAiP=(bu*^ zLAGsDO;c$-^h%M2ThR`-2U|oo>|RW@aCR_}TvE)isAW?_Y-ltlS%wwuwM?N&py_+e znMB_7;#Zt1xV5(ER&td9zQ7NZf=n27BsGrm&VjTPy0ph_)8n7RS|5ixMU}exZKP`_6W6Ks}g*z$&B_#uGem e0ek}xs+)sswkW8xOchZ7i@744C`cQuude`@>Mdaa delta 1798 zcmV+h2l@D{4z>;vLRx4!F+o`-Q(13-(~tlc#gP#qG*AMlkSRc*00005Mrkx?Xc+)x z0000D8&CiM00001#)gK5fM^Ur&=~*#X`lh182|tP$B|JfeUy7I zNh9?{K{Xo-aZB9L;Sf)b1rv`kAFCWv8S2~3%w9myaO(0~8{pW#qLMdM3I z;E14LiW-n;CHN?`6;dFM(Lhi=BtcJ+5lH|U6|_MqEf5f-Rz(>F*COPR_d;mEEU1-W zukvBC$(lyy7)nur5wM1_vyOnfF;MJQez!FssaaB4f7aU$8$=^?jb~~r<^OLxV+Yw)Ww-k8(}z?Gqa;vhui#N?l}~I5;WGKSoY&gqzt(RB&&{ z8^`O;f97d4l4G7d47fCJG;1W<$+BY2%&Mf^(GpG`J+;}2P3A6UD=M}O#&N-SamKK& zjj@}woha+@ZO3cIMy{qcqTM)nda~1A#Nfj%%(B&%nX);tV{A7>kscJ1L|Bj^0wM{S z5D`r1D51qzs9q8RB9=)MmO@2T3b6`VA}VX-e^F5qrHCzXR*1z0EEYndSsiBq;{{Iu zz%ZI5PYP7*PM>dT8c6lNtYMCe63~zv(u7G6 zy#kaPMo39mn*!nt(0l_@?Y1f%0ptx@;H%*qgM4Zi$N_8vNH81oB1!#3-ZURG`_6BZ zf9Xm6gRLg?`ZNQedo%E(-+gaVPne$gSIC3;7#N89bz$S;I%^a!37R(se-O(PEFJPE>PYi+Xzg_A-c4RaJIxME3XxBX zd%_eR`{-mc@RNM@qr68`1g%9xOGc=N=#AAJi!2>Xf=v6Q7#cf$ z0~E;eo=20wT(L_PTk$Zlig|SQlhRLWKN%Z5?((FyQ;!J}PNEGE?GIRcuKDt+e^q$T zh9iS7OW|`M#78-!pi1d`&iLymf*uScz{1%)Vi*|{nJatxA5p!%)zHh6dZkq(t;$0P zPCFCNx%@pYxa3O(kwsvkV4JlwOKK~1MPMLf0;iqzJ|bs)EQ;rEVLXy=k{xG>6J}kb zi}Rg{CgJBl?GA*AquM%KJ6xUoe?*lMO9ygN$`u{jv{_l-oGfbNZMNO=L);rQ8<1s0;!Q}^%w1Oz9G|xFxRdfNER(qe zdAqt~Njg}v6Ojc7u^kLDKS{+URVC}bR8I&gDvb76!}PJw}9ZFF;LG^wj(msXfVOk!sBwsA)xfyipw+Z?L*X) zfYlySdmof~p2J}cWQWF&e{~(wc8?U19LDEVPUR`|H5S@6&{D{cBGzU zkNp#+M+&YH`r9CSZfB9e9$wpXZG#D{ai4}^9 zlF?TfNbFf9R#rq>ON>d0BC15dqbQzlJL4L(k~oK0bw4XCs!Ef{fAHbBoT99y4#$bk zM4BA6CKdOXb(T*!-6Wp8w>Jz172OftA){fqW5apgX|hgn79@2zlOtE9+^-WY8_x7k zJxPhVD0&Bt&^!GpyQF&Gam5Y}BdrtcC*xraNuyoq)}pOTrXnrOSKS9Vj5}JYsn2e*$WL{%iv}E&R}oS)h|47A=8qqgbT_xib&Nj(ba$YhmKsP(L9@^| zp;E}Lq%=vMf;k_DzraktI#0}>y+!=cpvFcRs1!*Ml0=a)G(jm5MwwWJ`hV*=+ky}9 o`%&;Dk}65b9`bb$5PhPmZ4JWUqN2?pRYU$R Date: Mon, 29 Nov 2021 14:12:18 +0100 Subject: [PATCH 28/28] test: refactored test_OK_column_standards --- tests/testthat/test_OK_column_standards.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test_OK_column_standards.R b/tests/testthat/test_OK_column_standards.R index e974f25..e26cd5c 100644 --- a/tests/testthat/test_OK_column_standards.R +++ b/tests/testthat/test_OK_column_standards.R @@ -1,7 +1,6 @@ library(NVIdb) library(OKplan) library(testthat) -context("OK_column_standards") test_that("Standard colwidths in Excel for OK-selections", { # Generate data frame with column names for table that should be exported to Excel @@ -34,7 +33,7 @@ test_that("Standard colwidths in Excel for OK-selections", { # Compare Add fylke, current fylkenr and current fylke with correct result expect_identical(standardize_columns(data = df, - dbsource = "sau_brucella_slakteri", + dbsource = "ok_blodprover_slakteri", standards = OK_column_standards, property = "colwidths_Excel"), correct_result) @@ -74,7 +73,7 @@ test_that("Standard collabels for OK selections", { # Compare Add fylke, current fylkenr and current fylke with correct result expect_identical(standardize_columns(data = df, - dbsource = "sau_brucella_slakteri", + dbsource = "ok_blodprover_slakteri", standards = OK_column_standards, property = "collabels"), correct_result)