Skip to content

Commit 29c165e

Browse files
authored
Merge pull request #7 from NorwegianVeterinaryInstitute/develop
NVIdb v0.5.3
2 parents ccbeb92 + 62fa3d2 commit 29c165e

File tree

7 files changed

+159
-127
lines changed

7 files changed

+159
-127
lines changed

DESCRIPTION

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: NVIdb
22
Title: Facilitating use of Norwegian Veterinary Institute's databases
3-
Version: 0.5.2
4-
Date: 2021-04-24
3+
Version: 0.5.3
4+
Date: 2021-05-07
55
Authors@R:
66
c(person(given = "Petter",
77
family = "Hopp",
@@ -29,27 +29,28 @@ License: BSD_3_clause + file LICENSE
2929
Encoding: UTF-8
3030
LazyData: true
3131
Imports:
32-
utils,
3332
stats,
33+
utils,
34+
checkmate,
35+
data.table,
36+
dplyr,
3437
getPass,
35-
svDialogs,
3638
keyring,
37-
RODBC,
38-
snakecase,
3939
magrittr,
40-
checkmate,
4140
poorman (>= 0.2.3),
42-
data.table
41+
RODBC,
42+
snakecase,
43+
svDialogs
4344
RoxygenNote: 7.1.1
4445
Suggests:
45-
spelling,
46+
devtools,
47+
knitr,
4648
remotes,
47-
testthat,
49+
rmarkdown,
4850
roxygen2,
49-
withr,
50-
devtools,
51+
spelling,
5152
styler,
52-
knitr,
53-
rmarkdown
53+
testthat,
54+
withr
5455
VignetteBuilder: knitr
5556
Language: en-GB

NEWS

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
NVIdb 0.5.3 - (2021-05-07)
2+
--------------------------
3+
4+
New features:
5+
6+
- add_PJS_code_description now translates registertype (type of location or address) and konkl_type (conclusion type) to descriptive text.
7+
8+
- standardize_PJSdata now transforms sak_forst_avsluttet (from v_innsendelse) to date format.
9+
10+
11+
Bug fixes:
12+
13+
- There was a problem with standardize_columns and the function was rewritten to use dplyr in stead of poorman.
14+
15+
116
NVIdb 0.5.2 - (2021-04-24)
217
--------------------------
318

R/add_PJS_code_description.R

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@
1111
#' The function uses a premade translation table (PJS_codes_2_text.csv) that normally is updated every night from PJS.
1212
#'
1313
#' Currently, the translation table has PJS-codes and the corresponding description for the following PJS variable types:
14-
#' hensikt,
15-
#' utbrudd,
16-
#' art,
17-
#' artrase,
18-
#' driftsform,
19-
#' provetype,
20-
#' provemateriale,
21-
#' kjonn,
22-
#' forbehandling,
23-
#' fysiologisk_stadium,
24-
#' metode,
25-
#' kjennelse,
26-
#' analytt,
27-
#' seksjon.
14+
#' \itemize{
15+
#' \item hensikt
16+
#' \item utbrudd
17+
#' \item registertype (categories for locations and addresses)
18+
#' \item seksjon
19+
#' \item art (species and breed codes to species name)
20+
#' \item artrase (species and breed codes to species or breed name)
21+
#' \item driftsform
22+
#' \item provetype
23+
#' \item provemateriale
24+
#' \item kjonn
25+
#' \item forbehandling
26+
#' \item fysiologisk_stadium
27+
#' \item metode
28+
#' \item konkl_type
29+
#' \item kjennelse
30+
#' \item analytt.
31+
#' }
2832
#'
2933
#' \code{position =} is used to give the place if the new columns in the data.frame. For \code{position = "right"} the new variables are
3034
#' placed to the right of the code_variable. Likewise, for \code{position = "left"} the new variables are placed to the left of the

R/standardize_PJSdata.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ standardize_PJSdata <- function(PJSdata, dbsource = "v2_sak_m_res") {
5757

5858
# Change to date for date-variables
5959
# Done before trimming character variables to reduce variables that needs to be trimmed
60-
cols_2_modify <- intersect(colnames(PJSdata), c("mottatt", "uttatt", "avsluttet",
60+
cols_2_modify <- intersect(colnames(PJSdata), c("mottatt", "uttatt", "avsluttet", "sak_forst_avsluttet",
6161
"uttatt_parprove", "mottatt_parprove",
6262
"und_godkjent", "und_avsluttet"))
6363
PJSdata[,cols_2_modify] <- lapply(PJSdata[,cols_2_modify], as.Date, format = "%d.%m.%y")

R/standardize_columns.R

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ standardize_columns <- function(data,
115115

116116
# Reading column standards from a csv-file based on in an Excel file
117117
if (is.null(standards)) {
118-
column_standards <- utils::read.csv2(file = paste0(set_dir_NVI("ProgrammeringR"),"standardization/column_standards.csv"),
118+
column_standards <- utils::read.csv2(file = paste0(NVIdb::set_dir_NVI("ProgrammeringR"),"standardization/column_standards.csv"),
119119
fileEncoding = "UTF-8")
120120
} else {
121121
column_standards <- standards
@@ -131,10 +131,10 @@ standardize_columns <- function(data,
131131

132132
standard <- column_standards %>%
133133
# Filter to include only information for relevant column names and with property information
134-
poorman::filter(colname_db %in% columnnames$V1) %>%
135-
poorman::filter(!is.na(colname)) %>%
136-
poorman::select(table_db, colname_db, colname) %>%
137-
poorman::distinct()
134+
dplyr::filter(colname_db %in% columnnames$V1) %>%
135+
dplyr::filter(!is.na(colname)) %>%
136+
dplyr::select(table_db, colname_db, colname) %>%
137+
dplyr::distinct()
138138

139139
# Keep information on relevant table name and combine information for all other tables
140140
standard[which(standard$table_db != dbsource), "table_db"] <- NA
@@ -143,12 +143,12 @@ standardize_columns <- function(data,
143143
if (dim(standard)[1] > 0) {
144144
standard <- standard %>%
145145
# Identify column names with only one suggested column width
146-
poorman::add_count(colname_db, name = "n") %>%
147-
poorman::ungroup() %>%
146+
dplyr::add_count(colname_db, name = "n") %>%
147+
dplyr::ungroup() %>%
148148
# Select column width either if only one suggested or for the current table
149-
poorman::filter(n == 1 | table_db == dbsource & n > 1) %>%
150-
poorman::select(colname_db, colname) %>%
151-
poorman::distinct()
149+
dplyr::filter(n == 1 | table_db == dbsource & n > 1) %>%
150+
dplyr::select(colname_db, colname) %>%
151+
dplyr::distinct()
152152
}
153153

154154
# # Standardize column names
@@ -218,10 +218,10 @@ standardize_columns <- function(data,
218218
# Standard labels in Norwegian is always generated as is used to impute missing labels in other languages
219219
standard <- column_standards %>%
220220
# Filter to include only information for relevant column names and with property information
221-
poorman::filter(colname %in% collabels$V1) %>%
222-
poorman::filter(!is.na(label_1_no)) %>%
223-
poorman::select(table_db, colname, label_1_no) %>%
224-
poorman::distinct()
221+
dplyr::filter(colname %in% collabels$V1) %>%
222+
dplyr::filter(!is.na(label_1_no)) %>%
223+
dplyr::select(table_db, colname, label_1_no) %>%
224+
dplyr::distinct()
225225

226226
# Keep information on relevant table name and combine information for all other tables
227227
standard[which(standard$table_db != dbsource), "table_db"] <- NA
@@ -230,21 +230,21 @@ standardize_columns <- function(data,
230230
if (dim(standard)[1] > 0) {
231231
standard <- standard %>%
232232
# Identify column names with only one suggested column width
233-
poorman::add_count(colname, name = "n") %>%
234-
poorman::ungroup() %>%
233+
dplyr::add_count(colname, name = "n") %>%
234+
dplyr::ungroup() %>%
235235
# Select column width either if only one suggested or for the current table
236-
poorman::filter(n == 1 | table_db == dbsource & n > 1) %>%
237-
poorman::select(colname = colname, label = label_1_no) %>%
238-
poorman::distinct()
236+
dplyr::filter(n == 1 | table_db == dbsource & n > 1) %>%
237+
dplyr::select(colname = colname, label = label_1_no) %>%
238+
dplyr::distinct()
239239
}
240240

241241
## English column labels ----
242242
if (language == "en") {
243243
standard_en <- column_standards %>%
244-
poorman::filter(colname %in% collabels$V1) %>%
245-
poorman::filter(!is.na(label_1_en)) %>%
246-
poorman::select(table_db, colname, label_1_en) %>%
247-
poorman::distinct()
244+
dplyr::filter(colname %in% collabels$V1) %>%
245+
dplyr::filter(!is.na(label_1_en)) %>%
246+
dplyr::select(table_db, colname, label_1_en) %>%
247+
dplyr::distinct()
248248

249249
# Keep information on relevant table name and combine information for all other tables
250250
standard_en[which(standard_en$table_db != dbsource), "table_db"] <- NA
@@ -253,18 +253,18 @@ standardize_columns <- function(data,
253253
if (dim(standard_en)[1] > 0) {
254254
standard_en <- standard_en %>%
255255
# Identify column names with only one suggested column width
256-
poorman::add_count(colname, name = "n") %>%
257-
poorman::ungroup() %>%
258-
poorman::filter(n == 1 | table_db == dbsource & n > 1) %>%
259-
poorman::select(colname, label_1_en) %>%
260-
poorman::distinct()
256+
dplyr::add_count(colname, name = "n") %>%
257+
dplyr::ungroup() %>%
258+
dplyr::filter(n == 1 | table_db == dbsource & n > 1) %>%
259+
dplyr::select(colname, label_1_en) %>%
260+
dplyr::distinct()
261261
}
262262

263263
# Impute missing labels with Norwegian labels
264264
standard <- standard_en %>%
265-
poorman::full_join(standard, by = c("colname" = "colname")) %>%
266-
poorman::mutate(label = poorman::coalesce(label_1_en, label)) %>%
267-
poorman::select(colname, label)
265+
dplyr::full_join(standard, by = c("colname" = "colname")) %>%
266+
dplyr::mutate(label = dplyr::coalesce(label_1_en, label)) %>%
267+
dplyr::select(colname, label)
268268
}
269269

270270
## Impute Sentence case for those without defined label ----¨
@@ -302,13 +302,13 @@ standardize_columns <- function(data,
302302
# Standardize colwidths
303303
standard <- column_standards %>%
304304
# Filter to include only information for relevant column names and with property information
305-
poorman::filter(colname %in% colwidths$V1) %>%
306-
poorman::filter(!is.na(colwidth_Excel)) %>%
307-
poorman::select(table_db = table_db, colname = colname, colwidth = colwidth_Excel)
305+
dplyr::filter(colname %in% colwidths$V1) %>%
306+
dplyr::filter(!is.na(colwidth_Excel)) %>%
307+
dplyr::select(table_db = table_db, colname = colname, colwidth = colwidth_Excel)
308308
# uses which below as there seem to be a bug so that case_when doesn't work properly within a function
309-
# poorman::mutate(table_db = poorman::case_when(table_db == "dbsource" ~ table_db,
309+
# dplyr::mutate(table_db = dplyr::case_when(table_db == "dbsource" ~ table_db,
310310
# TRUE ~ as.character(NA))) %>%
311-
# poorman::distinct()
311+
# dplyr::distinct()
312312
# Keep information on relevant table name and combine information for all other tables
313313
standard[which(standard$table_db != dbsource), "table_db"] <- NA
314314
standard <- unique(standard)
@@ -317,12 +317,12 @@ standardize_columns <- function(data,
317317
if (dim(standard)[1] > 0) {
318318
standard <- standard %>%
319319
# Identify column names with only one suggested column width
320-
poorman::add_count(colname, name = "n") %>%
321-
poorman::ungroup() %>%
320+
dplyr::add_count(colname, name = "n") %>%
321+
dplyr::ungroup() %>%
322322
# Select column width either if only one suggested or for the current table
323-
poorman::filter(n == 1 | table_db == dbsource & n > 1) %>%
324-
poorman::select(colname, colwidth) %>%
325-
poorman::distinct()
323+
dplyr::filter(n == 1 | table_db == dbsource & n > 1) %>%
324+
dplyr::select(colname, colwidth) %>%
325+
dplyr::distinct()
326326
}
327327

328328
# New column with standard column names¨
@@ -356,17 +356,17 @@ standardize_columns <- function(data,
356356
# Standard labels in Norwegian is always generated as is used to impute missing labels in other languages
357357
standard <- column_standards %>%
358358
# Filter to include only information for relevant column names and with property information
359-
poorman::filter(table_db == dbsource) %>%
360-
poorman::filter(colname %in% columnorder$V1) %>%
361-
poorman::filter(!is.na(colorder)) %>%
362-
poorman::select(colname, colorder) %>%
363-
poorman::distinct() %>%
359+
dplyr::filter(table_db == dbsource) %>%
360+
dplyr::filter(colname %in% columnorder$V1) %>%
361+
dplyr::filter(!is.na(colorder)) %>%
362+
dplyr::select(colname, colorder) %>%
363+
dplyr::distinct() %>%
364364
# removes colorders with more than suggested position
365-
poorman::add_count(colname, name = "n") %>%
366-
poorman::filter(n == 1) %>%
367-
poorman::select(colname, colorder)
365+
dplyr::add_count(colname, name = "n") %>%
366+
dplyr::filter(n == 1) %>%
367+
dplyr::select(colname, colorder)
368368
# Sort according to first column, replaced by order
369-
# poorman::arrange(colorder)
369+
# dplyr::arrange(colorder)
370370

371371
standard <- standard[order(standard$colorder),]
372372

0 commit comments

Comments
 (0)