Skip to content

Commit fe58286

Browse files
authored
Merge pull request #14 from NorwegianVeterinaryInstitute/dev
NVIpjsr v0.1.1
2 parents 03d2b7a + 0e90591 commit fe58286

34 files changed

+676
-744
lines changed

DESCRIPTION

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: NVIpjsr
22
Title: Tools to facilitate working with PJS data
3-
Version: 0.1.0
4-
Date: 2024-05-03
3+
Version: 0.1.1
4+
Date: 2024-08-19
55
Authors@R: c(
66
person("Petter", "Hopp", , "Petter.Hopp@vetinst.no", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0002-8695-0378")),
@@ -16,7 +16,7 @@ License: BSD_3_clause + file LICENSE
1616
URL: https://github.com/NorwegianVeterinaryInstitute/NVIpjsr
1717
BugReports: https://github.com/NorwegianVeterinaryInstitute/NVIpjsr/issues
1818
Depends:
19-
R (>= 4.0.0)
19+
R (>= 4.1.0)
2020
Encoding: UTF-8
2121
Language: en-GB
2222
Roxygen: list(markdown = FALSE)
@@ -26,7 +26,6 @@ Imports:
2626
data.table,
2727
DBI,
2828
dplyr,
29-
magrittr,
3029
stats,
3130
NVIcheckmate (>= 0.7.0),
3231
NVIdb (>= 0.11.2)

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(add_PJS_code_description)
4-
export(assert_read_functions)
54
export(build_query_hensikt)
65
export(build_query_one_disease)
76
export(build_query_outbreak)
@@ -19,4 +18,3 @@ export(set_disease_parameters)
1918
export(standardize_PJSdata)
2019
export(standardize_eos_data)
2120
export(transform_code_combinations)
22-
importFrom(magrittr,"%>%")

NEWS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
# NVIpjsr 0.1.1 - (2024-08-19)
2+
3+
## New features:
4+
5+
-
6+
7+
8+
## Bug fixes:
9+
10+
- `retrieve_PJSdata` now accepts additional arguments in dots.
11+
12+
- The build_query-functions now correctly calls `NVIpjsr::build_sql_select_year` and `NVIpjsr::build_sql_select_code`.
13+
14+
- `choose_PJS_levls` now correctly calls `NVIpjsr::PJS_levels`.
15+
16+
- `select_PJSdata_for_value` now correctly calls `NVIpjsr::PJS_levels`.
17+
18+
19+
## Other changes:
20+
21+
- `NVIpjsr` now uses the internal pipe "|>" and therefore require R >= 4.1.0.
22+
23+
- simplified code for some functions.
24+
25+
26+
## BREAKING CHANGES:
27+
28+
-
29+
30+
131
# NVIpjsr 0.1.0 - (2024-05-03)
232

333
## First release

R/add_PJS_code_description.R

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,13 @@
141141
#' @param filename [\code{character(1)}] \cr
142142
#' File name of the source file for the translation table for PJS codes.
143143
#' @param from_path [\code{character(1)}] \cr
144-
#' Path for the source translation table for PJS codes.
144+
#' Path for the source files used to generate the translation table. Defaults
145+
#' to \code{file.path(NVIdb::set_dir_NVI("Provedata_Rapportering", slash = FALSE), "FormaterteData")}.
145146
#' @param to_path [\code{character(1)}] \cr
146-
#' Path for the target translation table for PJS codes when copying the
147-
#' translation table.
147+
#' Path to which the source files for generating the translation table should
148+
#' be copied.
149+
#' @param \dots Other arguments to be passed to
150+
#' \ifelse{html}{\code{\link[utils:read.csv2]{utils::read.csv2}}}{\code{utils::read.csv2}}.
148151
#'
149152
#' @return \code{add_PJS_code_description} A data frame where the description text
150153
#' for the PJS code has been added in the column to the right of the column
@@ -159,7 +162,6 @@
159162
#' copied if it is newer than the target file.
160163
#'
161164
#' @author Petter Hopp Petter.Hopp@@vetinst.no
162-
#' @importFrom magrittr %>%
163165
#' @export
164166
#' @examples
165167
#' \dontrun{
@@ -221,11 +223,11 @@ add_PJS_code_description <- function(data,
221223
impute_old_when_missing = FALSE) {
222224

223225
if (PJS_variable_type[1] == "auto" | new_column[1] == "auto") {
224-
code_description_colname <- NVIdb::PJS_code_description_colname
226+
code_description_colname <- NVIpjsr::PJS_code_description_colname
225227
if (isTRUE(backward)) {
226228
code_description_colname <- dplyr::rename(code_description_colname, new_column = code_colname, code_colname = new_column)
227229
}
228-
PJS_types_selected <- as.data.frame(code_colname) %>%
230+
PJS_types_selected <- as.data.frame(code_colname) |>
229231
dplyr::left_join(code_description_colname, by = "code_colname")
230232
PJS_types_selected <- subset(PJS_types_selected, !is.na(PJS_types_selected$type))
231233
}
@@ -348,18 +350,9 @@ add_PJS_code_description <- function(data,
348350
kode_nr <- which(column_names == "kode")
349351
column_names[c(navn_nr, kode_nr)] <- c("kode", "navn")
350352
colnames(code_2_description) <- column_names
351-
code_2_description <- code_2_description %>%
353+
code_2_description <- code_2_description |>
352354
dplyr::add_count(dplyr::across(c("type", "kode")), name = "antall")
353355

354-
355-
# code_2_description <- code_2_description %>%
356-
# dplyr::mutate(navn = tolower(.data$navn)) %>%
357-
# dplyr::distinct() %>%
358-
# dplyr::rename(kode = .data$navn, navn = .data$kode) %>%
359-
# dplyr::filter(is.na(.data$utgatt_dato)) %>%
360-
# dplyr::add_count(.data$type, .data$kode, name = "antall") %>%
361-
# dplyr::filter(.data$antall == 1) %>%
362-
# dplyr::select(-.data$antall)
363356
code_2_description <- subset(code_2_description, code_2_description$antall == 1)
364357
code_2_description$antall <- NULL
365358

R/assert_arguments.R

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,65 @@
44
# - assert_read_function
55
# - assert_copy_function
66
#
7-
#' @title Collection of assertions for copy_functions
8-
#' @description Collection of assertions used in standard copy_functions.
9-
#'
10-
#' @details All copy functions have the same arguments and the
11-
#' assertion can be standardized. The assertion of \code{filname} is
12-
#' constructed to handle both character and list input.
13-
#'
14-
#' The assertion is based on removing ending "\\" and "/" from
15-
#' \code{from_path} and \code{to_path} before the assertion is performed.
16-
#'
17-
#' @param filename Argument to the copy-function to be asserted.
18-
#' @param from_path Argument to the copy-function to be asserted. Ending
19-
#' "\\" and "/" should have been removed before the assertion is performed.
20-
#' @param to_path Argument to the copy-function to be asserted. Ending
21-
#' "\\" and "/" should have been removed before the assertion is performed.
22-
#'
23-
#' @return \code{TRUE} if none of the assertions failed. If any of the assertions
24-
#' failed, one or more error messages are returned.
25-
#'
26-
#' @author Petter Hopp Petter.Hopp@@vetinst.no
27-
#' @keywords internal
28-
#'
29-
#'
30-
assert_copy_function <- function(filename,
31-
from_path,
32-
to_path) {
33-
34-
# ARGUMENT CHECKING ----
35-
# Object to store check-results
36-
checks <- checkmate::makeAssertCollection()
37-
38-
# Perform checks
39-
## filename
40-
checkmate::assert(checkmate::check_character(filename,
41-
min.chars = 1,
42-
len = 1),
43-
checkmate::check_list(filename, min.len = 1),
44-
combine = "or",
45-
add = checks)
46-
47-
# checkmate::assert_list(filename, len = 2, add = checks)
48-
# # from_path
49-
# checkmate::assert_character(from_path, len = 1, min.chars = 1, add = checks)
50-
# if (endsWith(from_path, "/")) {
51-
# checkmate::assert_directory_exists(substr(from_path, 1, nchar(from_path) - 1), access = "r", add = checks)
52-
# } else {
53-
# checkmate::assert_directory_exists(from_path, access = "r", add = checks)
54-
# }
55-
56-
## from_path / filename
57-
for (i in c(1:length(filename))) {
58-
checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = checks)
59-
}
60-
## to_path
61-
checkmate::assert_directory_exists(to_path, access = "r", add = checks)
62-
63-
# Report check-results
64-
checkmate::reportAssertions(checks)
65-
}
7+
# #' @title Collection of assertions for copy_functions
8+
# #' @description Collection of assertions used in standard copy_functions.
9+
# #'
10+
# #' @details All copy functions have the same arguments and the
11+
# #' assertion can be standardized. The assertion of \code{filname} is
12+
# #' constructed to handle both character and list input.
13+
# #'
14+
# #' The assertion is based on removing ending "\\" and "/" from
15+
# #' \code{from_path} and \code{to_path} before the assertion is performed.
16+
# #'
17+
# #' @param filename Argument to the copy-function to be asserted.
18+
# #' @param from_path Argument to the copy-function to be asserted. Ending
19+
# #' "\\" and "/" should have been removed before the assertion is performed.
20+
# #' @param to_path Argument to the copy-function to be asserted. Ending
21+
# #' "\\" and "/" should have been removed before the assertion is performed.
22+
# #'
23+
# #' @return \code{TRUE} if none of the assertions failed. If any of the assertions
24+
# #' failed, one or more error messages are returned.
25+
# #'
26+
# #' @author Petter Hopp Petter.Hopp@@vetinst.no
27+
# #' @keywords internal
28+
# #'
29+
# #'
30+
# assert_copy_function <- function(filename,
31+
# from_path,
32+
# to_path) {
33+
#
34+
# # ARGUMENT CHECKING ----
35+
# # Object to store check-results
36+
# checks <- checkmate::makeAssertCollection()
37+
#
38+
# # Perform checks
39+
# ## filename
40+
# checkmate::assert(checkmate::check_character(filename,
41+
# min.chars = 1,
42+
# len = 1),
43+
# checkmate::check_list(filename, min.len = 1),
44+
# combine = "or",
45+
# add = checks)
46+
#
47+
# # checkmate::assert_list(filename, len = 2, add = checks)
48+
# # # from_path
49+
# # checkmate::assert_character(from_path, len = 1, min.chars = 1, add = checks)
50+
# # if (endsWith(from_path, "/")) {
51+
# # checkmate::assert_directory_exists(substr(from_path, 1, nchar(from_path) - 1), access = "r", add = checks)
52+
# # } else {
53+
# # checkmate::assert_directory_exists(from_path, access = "r", add = checks)
54+
# # }
55+
#
56+
# ## from_path / filename
57+
# for (i in c(1:length(filename))) {
58+
# checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = checks)
59+
# }
60+
# ## to_path
61+
# checkmate::assert_directory_exists(to_path, access = "r", add = checks)
62+
#
63+
# # Report check-results
64+
# checkmate::reportAssertions(checks)
65+
# }
6666

6767
# #' @title Collection of assertions for add_functions
6868
# #' @description Collection of assertions used in standard add_functions.
@@ -162,64 +162,64 @@ assert_copy_function <- function(filename,
162162
# }
163163

164164

165-
#' @title Collection of assertions for read_functions
166-
#' @description Collection of assertions used in standard read_functions.
167-
#'
168-
#' @details All read functions include the same arguments and the
169-
#' assertion can be standardized. The assertion of \code{filname} is
170-
#' constructed to handle both character and list input.
171-
#'
172-
#' The assertion is based on removing ending "\\" and "/" from
173-
#' \code{from_path} before the assertion is performed.
174-
175-
#' The assertCollection must be set up separately and is used as input argument, see example.
176-
#'
177-
#' @param filename Argument to the function to be asserted.
178-
#' @param from_path Argument to the function to be asserted. Ending
179-
#' "\\" and "/" must have been removed before the assertion is performed.
180-
#' @param add assertCollection.
181-
#'
182-
#' @return An assertCollection that have been updated with the results of assertions for \code{filename} and \code{from_path}.
183-
#'
184-
#' @author Petter Hopp Petter.Hopp@@vetinst.no
185-
#' @keywords internal
186-
#' @export
187-
#'
188-
#' @examples
189-
#' # Attach package and make temporary directory
190-
#' library(NVIdb)
191-
#' td <- tempdir()
192-
#' write.csv2(NVIdb::PJS_levels, file = file.path(td, "PJS_levels.csv"))
193-
#'
194-
#' # ARGUMENT CHECKING
195-
#' # Object to store check-results
196-
#' checks <- checkmate::makeAssertCollection()
197-
#' # Perform checks
198-
#' checks <- assert_read_functions(filename = "PJS_levels.csv",
199-
#' from_path = td,
200-
#' add = checks)
201-
#' # Report check-results
202-
#' checkmate::reportAssertions(checks)
203-
assert_read_functions <- function(filename,
204-
from_path,
205-
add) {
206-
207-
checkmate::assert_class(x = add, classes = "AssertCollection")
208-
209-
# Perform checks ----
210-
211-
## filename
212-
checkmate::assert(checkmate::check_character(filename,
213-
min.chars = 1, len = 1,
214-
any.missing = FALSE),
215-
checkmate::check_list(filename,
216-
min.len = 1,
217-
any.missing = FALSE),
218-
combine = "or",
219-
add = add)
220-
## from_path / filename
221-
for (i in c(1:length(filename))) {
222-
checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = add)
223-
}
224-
return(add)
225-
}
165+
# #' @title Collection of assertions for read_functions
166+
# #' @description Collection of assertions used in standard read_functions.
167+
# #'
168+
# #' @details All read functions include the same arguments and the
169+
# #' assertion can be standardized. The assertion of \code{filname} is
170+
# #' constructed to handle both character and list input.
171+
# #'
172+
# #' The assertion is based on removing ending "\\" and "/" from
173+
# #' \code{from_path} before the assertion is performed.
174+
#
175+
# #' The assertCollection must be set up separately and is used as input argument, see example.
176+
# #'
177+
# #' @param filename Argument to the function to be asserted.
178+
# #' @param from_path Argument to the function to be asserted. Ending
179+
# #' "\\" and "/" must have been removed before the assertion is performed.
180+
# #' @param add assertCollection.
181+
# #'
182+
# #' @return An assertCollection that have been updated with the results of assertions for \code{filename} and \code{from_path}.
183+
# #'
184+
# #' @author Petter Hopp Petter.Hopp@@vetinst.no
185+
# #' @keywords internal
186+
# #' @export
187+
# #'
188+
# #' @examples
189+
# #' # Attach package and make temporary directory
190+
# #' library(NVIdb)
191+
# #' td <- tempdir()
192+
# #' write.csv2(NVIdb::PJS_levels, file = file.path(td, "PJS_levels.csv"))
193+
# #'
194+
# #' # ARGUMENT CHECKING
195+
# #' # Object to store check-results
196+
# #' checks <- checkmate::makeAssertCollection()
197+
# #' # Perform checks
198+
# #' checks <- assert_read_functions(filename = "PJS_levels.csv",
199+
# #' from_path = td,
200+
# #' add = checks)
201+
# #' # Report check-results
202+
# #' checkmate::reportAssertions(checks)
203+
# assert_read_functions <- function(filename,
204+
# from_path,
205+
# add) {
206+
#
207+
# checkmate::assert_class(x = add, classes = "AssertCollection")
208+
#
209+
# # Perform checks ----
210+
#
211+
# ## filename
212+
# checkmate::assert(checkmate::check_character(filename,
213+
# min.chars = 1, len = 1,
214+
# any.missing = FALSE),
215+
# checkmate::check_list(filename,
216+
# min.len = 1,
217+
# any.missing = FALSE),
218+
# combine = "or",
219+
# add = add)
220+
# ## from_path / filename
221+
# for (i in c(1:length(filename))) {
222+
# checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = add)
223+
# }
224+
# return(add)
225+
# }

0 commit comments

Comments
 (0)