-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from NorwegianVeterinaryInstitute/dev
OKplan v0.8.0
- Loading branch information
Showing
15 changed files
with
349 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,5 @@ vignettes/*.pdf | |
.Renviron | ||
|
||
inst/doc | ||
!vignettes/OKplan.pdf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#' @title Writes the surveillance selection to a standardised file. | ||
#' | ||
#' @description The surveillance selection is written to a standardised file. | ||
#' The file is standardised to include a standard set of columns and have | ||
#' the records in a standard order. | ||
#' @details The data is saved as an "okplan" file that will be used the source | ||
#' file when the selection list is generated. | ||
#' | ||
#' The function uses | ||
#' \ifelse{html}{\code{\link[NVIdb:standardize_columns]{NVIdb::standardize_columns}}}{\code{NVIdb::standardize_columns}}. | ||
#' to select and order the columns. The formatting information is taken from | ||
#' \code{\link{OK_column_standards}}. | ||
#' | ||
#' @param data [\code{data.frame}]\cr | ||
#' The sampling plan with the units to be reported. | ||
#' @param filename [\code{character(1)}]\cr | ||
#' The name of the csv file including extension. | ||
#' @param filepath [\code{character(1)}]\cr | ||
#' The path to the csv file. | ||
#' @param sortvar [\code{character}]\cr | ||
#' The sort order for the records in the csv-file. Defaults to | ||
#' c("ok_hensiktkode", "ok_driftsformkode", "statuskode", | ||
#' "prioritet_av_reserve", "eier_lokalitetnr") | ||
#' @param \dots Other arguments to be passed to | ||
#' \ifelse{html}{\code{\link[utils:write.csv2]{utils::write.csv2}}}{\code{utils::write.csv2}}. | ||
#' | ||
#' @return None. Saves a data frame with the selection in a standard csv file. | ||
#' | ||
#' @author Petter Hopp Petter.Hopp@@vetinst.no | ||
#' @export | ||
#' @examples | ||
#' \dontrun{ | ||
#' library(OKplan) | ||
#' td <- tempdir() | ||
#' okplan <- as.data.frame(list("ok_hensiktkode" = c("01002", "01002"), | ||
#' "ok_driftsformkode" = c("010202", "010202"), | ||
#' "statuskode" = c(1, 1), | ||
#' "prioritet_av_reserve" = c(NA, NA), | ||
#' "eier_lokalitetnr" = c("1101123456", "1102123456"))) | ||
#' write_okplan(data = okplan, | ||
#' filename = "okplan_species_disease", | ||
#' filepath = td) | ||
#' } | ||
save_okplan <- function(data, | ||
filename, | ||
filepath, | ||
sortvar = c("ok_hensiktkode", "ok_driftsformkode", | ||
"statuskode", "prioritet_av_reserve", | ||
"eier_lokalitetnr"), | ||
...) { | ||
|
||
# PREPARE ARGUMENTS BEFORE ARGUMENT CHECKING ---- | ||
## Remove trailing backslash or slash before testing path | ||
filepath <- sub("\\\\{1,2}$|/{1,2}$", "", filepath) | ||
|
||
# ARGUMENT CHECKING ---- | ||
## Object to store check-results | ||
checks <- checkmate::makeAssertCollection() | ||
## Perform checks | ||
### data | ||
checkmate::assert_data_frame(data, add = checks) | ||
checkmate::assert_character(filename, min.chars = 1, len = 1, add = checks) | ||
### filename and filepath | ||
checkmate::assert_character(filename, min.chars = 1, len = 1, add = checks) | ||
checkmate::assert_directory_exists(filepath) | ||
### order | ||
checkmate::assert_subset(sortvar, choices = colnames(data), add = checks) | ||
## Report check-results | ||
checkmate::reportAssertions(checks) | ||
|
||
|
||
# STANDARDISE AND SAVE DATA TO csv-FILE ---- | ||
## Standardise column order, exclude columns | ||
data <- NVIdb::standardize_columns(data, | ||
dbsource = "okplan", | ||
standards = OKplan::OK_column_standards, | ||
property = "colorder", | ||
exclude = TRUE) | ||
|
||
## Sort data in the order given by sortvar | ||
data <- data[do.call(base::order, data[, sortvar]), ] | ||
|
||
## write the data to the csv-file | ||
utils::write.csv2(data, | ||
file = file.path(filepath, filename), | ||
row.names = FALSE, | ||
...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.