Skip to content

Commit

Permalink
Merge pull request #27 from PetterHopp/main
Browse files Browse the repository at this point in the history
NVIdb v0.10.1 (2023-05-31)
  • Loading branch information
PetterHopp authored May 31, 2023
2 parents 6d63600 + 5564660 commit 917b724
Show file tree
Hide file tree
Showing 20 changed files with 514 additions and 92 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: NVIdb
Title: Tools to facilitate the use of NVI's databases
Version: 0.10.0
Date: 2023-04-18
Version: 0.10.1
Date: 2023-05-31
Authors@R:
c(person(given = "Petter",
family = "Hopp",
Expand Down
23 changes: 23 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
NVIdb 0.10.1 - (2023-05-31)
----------------------------------------

New features:

- add_PJS_code_description is extended so that analytt and kjennelse at sakskonklusjon-level can be translated when using the arguments `PJS_variable_type` = "auto" and `new_column` = "auto".


Bug fixes:

-


Other changes:

- Improved help by standardising argument description for a few functions.


BREAKING CHANGES:

-


NVIdb 0.10.0 - (2023-04-18)
----------------------------------------

Expand Down
7 changes: 4 additions & 3 deletions R/add_MT_omrader.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
#' new_column = c("MT_regionnavn" = "MT_region"))
#' }
#'
# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("komnr_2_MT_omrader")

add_MT_omrader <- function(data,
translation_table = komnr_2_MT_omrader,
code_column = c("komnr"),
Expand Down Expand Up @@ -155,3 +152,7 @@ add_MT_omrader <- function(data,

return(data)
}

# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("komnr_2_MT_omrader")

15 changes: 9 additions & 6 deletions R/add_PJS_code_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#'
#' \code{add_PJS_code_description} uses the pre made translation table
#' "PJS_codes_2_text.csv". The data need to be loaded by
#' \code{read_PJS_code_registers} before running \code{add_PJS_code_description},
#' \code{read_PJS_codes_2_text} before running \code{add_PJS_code_description},
#' see example. The file "PJS_codes_2_text.csv" is normally updated every night
#' from PJS.
#'
Expand Down Expand Up @@ -46,9 +46,11 @@
#' metode \tab metodekode \tab metode \tab \cr
#' metode \tab subund_metodekode \tab submetode \tab \cr
#' konkl_type \tab konkl_typekode \tab konkl_type \tab \cr
#' kjennelse \tab sakskonkl_kjennelsekode \tab sakskonkl_kjennelse \tab \cr
#' kjennelse \tab konkl_kjennelsekode \tab konkl_kjennelse \tab \cr
#' kjennelse \tab res_kjennelsekode \tab res_kjennelse \tab \cr
#' kjennelse \tab subres_kjennelsekode \tab subres_kjennelse \tab \cr
#' analytt \tab sakskonkl_analyttkode \tab sakskonkl_analytt \tab \cr
#' analytt \tab konkl_analyttkode \tab konkl_analytt \tab \cr
#' analytt \tab res_analyttkode \tab res_analytt \tab \cr
#' analytt \tab subres_analyttkode \tab subres_analytt \tab \cr
Expand Down Expand Up @@ -85,7 +87,7 @@
#' descriptive text strings, there are no unique translation. In these cases,
#' the code value is left empty.
#'
#' \code{read_PJS_code_registers} reads the file "PJS_codes_2_text.csv" into a
#' \code{read_PJS_codes_2_text} reads the file "PJS_codes_2_text.csv" into a
#' data frame that can be used by \code{add_PJS_code_description}. In standard
#' setting will the file read in the latest updated file from NVI's internal
#' network. If changing the \code{from_path}, the function can be used to read
Expand All @@ -101,7 +103,7 @@
#' other PJS variables, a data frame with the same column definition can be
#' constructed to translate new variables.
#'
#' \code{copy_PJS_code_registers} copies the file pjsCodeDescriptions.csv to
#' \code{copy_PJS_codes_2_text} copies the file pjsCodeDescriptions.csv to
#' a given directory.
#'
#' @param data [\code{data.frame}] \cr
Expand Down Expand Up @@ -208,9 +210,6 @@
#' impute_old_when_missing = TRUE)
#' }
#'
# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("PJS_codes_2_text")

add_PJS_code_description <- function(data,
translation_table = PJS_codes_2_text,
PJS_variable_type,
Expand Down Expand Up @@ -387,3 +386,7 @@ add_PJS_code_description <- function(data,
}
return(data)
}

# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("PJS_codes_2_text")

7 changes: 4 additions & 3 deletions R/add_kommune_fylke.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@
#' "kommune" = "gjeldende_kommune"))
#' }
#'
# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("kommune_fylke")

add_kommune_fylke <- function(data,
translation_table = kommune_fylke,
code_column = c("komnr"),
Expand Down Expand Up @@ -156,3 +153,7 @@ add_kommune_fylke <- function(data,

return(data)
}

# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("kommune_fylke")

70 changes: 49 additions & 21 deletions R/add_lokalitet.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
#' @title Manage adding extra information to aquaculture sites
#' @description Function to add a column with current aquaculture zone and/or coordinates. In addition there are
#' function to read the translation table.
#' @details \code{add_lokalitet} can be used to add aquaculture zone to aquaculture sites.
#' @description Function to add a column with current aquaculture
#' zone and/or geo-coordinates. In addition there are function
#' to read the translation table.
#' @details \code{add_lokalitet} can be used to add aquaculture
#' zone and/or geo-coordinates to aquaculture sites. The new
#' columns can be one or more of c("sone", "EastUTM_33N_WGS84",
#' "NorthUTM_33N_WGS84", "Longitude_WGS84", "Latitude_WGS84").
#' If the new columns in the result data frame should have
#' other names, \code{new_column} can be input as a named
#' vector, see examples.
#'
#' \code{position =} is used to give the place if the new columns in the data.frame. For \code{position = "right"} the new variables are
#' placed to the right of the code_variable. Likewise, for \code{position = "left"} the new variables are placed to the left of the
#' code_variable. If \code{position = "first"} or \code{position = "last"} the new columns are placed first or last, respectively, in the
#' data.frame. A special case occurs for \code{position = "keep"} which only has meaning when the new column has the same name as an existing
#' column and overwrite = TRUE. In these cases, the existing column will be overwritten with new data and have the same position.
#' \code{position} is used to give the position if the new columns
#' in the data.frame. For \code{position = "right"} the new
#' variables are placed to the right of the code_variable.
#' Likewise, for \code{position = "left"} the new variables
#' are placed to the left of the code_variable. If
#' \code{position = "first"} or \code{position = "last"} the
#' new columns are placed first or last, respectively, in the
#' data frame. A special case occurs for \code{position = "keep"}
#' which only has meaning when the new column has the same name
#' as an existing column and \code{overwrite = TRUE}. In these
#' cases, the existing column will be overwritten with new data
#' and have the same position.
#'
#' \code{read_sonetilhorighet} reads the file "sonetilhorighet.txt" into a data frame that can be used by other routines. Standard setting
#' will the file read in the latest updated file from NVI's internal network. If changing the from_path, the function can be used to read
#' the translation file from other directories. This can be useful if having a stand alone app with no connection the NVI's internal
#' network. In other cases, it should be avoided.
#' \code{read_sonetilhorighet} reads the file "sonetilhorighet.txt"
#' into a data frame that can be used by other routines. Standard
#' setting will the file read in the latest updated file from
#' NVI's internal network. If changing the from_path, the
#' function can be used to read the translation file from
#' other directories. This can be useful if having a stand
#' alone app with no connection the NVI's internal network.
#' In other cases, it should be avoided.
#'
#' @param data Data frame with data with a column with a aquaculture site number ("LokNr")
#' @param translation_table Data frame with the table for translating from loknr to the property in question.
#' @param code_column The column with the coded value. Valid values are one of c("LokNr"). If the column in
#' @param data [\code{data.frame}]\cr
#' Data with a column with an aquaculture site number ("LokNr")
#' @param translation_table [\code{data.frame}]\cr
#' Table for translating from loknr to the property in question.
#' @param code_column [\code{character(1)}]\cr
#' The column with the coded value. Valid values are one of c("LokNr"). If the column in
#' data has another name, it can be input as a named vector, see examples.
#' @param new_column The new columns that should be included into the data frame. The new columns can be one ore more of
#' c("sone", "EastUTM_33N_WGS84", "NorthUTM_33N_WGS84", "Longitude_WGS84", "Latitude_WGS84"). If the new columns in the result
#' data frame should have other names, \code{new_column} can be input as a named vector, see examples.
#' @param new_column [\code{character}]\cr
#' The new columns that should be included into the data frame.
#' @template position
#' @template overwrite
#' @param filename a list with the filenames of the source files with the tables for generating the translation table.
#' @param from_path Path for the source files for the translation table.
#' @param filename [\code{list}]\cr
#' The filenames of the source files with the tables for generating the translation table.
#' @param from_path [\code{character(1)}]\cr
#' Path for the source files for the translation table.
#'
#' @return \code{add_lokalitet} A data frame where the aquaculture zone and / or coordinates have been added in the column to the
#' @return \code{add_lokalitet}: \code{data.frame} where the aquaculture
#' zone and / or geo-coordinates have been added in the column to the
#' right of the column with the LokNr.
#'
#' \code{read_sonetilhorighet}: \code{data.frame} with "LokNr",
#' aquaculture zone and geo-coordinates. If not changing standard
#' input to the function, the standard file at NVI's internal
#' network is read.
#'
#' @author Petter Hopp Petter.Hopp@@vetinst.no
#' @export
#' @examples
Expand Down
6 changes: 4 additions & 2 deletions R/add_poststed.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
#' new_column = c("poststed", "postkomnr" = "komnr"))
#' }
#'
# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("poststed")

add_poststed <- function(data,
translation_table = poststed,
Expand Down Expand Up @@ -127,3 +125,7 @@ add_poststed <- function(data,

return(data)
}


# To avoid checking of the variable kommune_fylke as default input argument in the function
utils::globalVariables("poststed")
14 changes: 14 additions & 0 deletions R/ignore_unused_imports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Remove NOTE when running CMD check and checking dependencies
# Namespaces in Imports field not imported from:
# 'NVIrpackages' 'rlang' 'rmarkdown' 'shiny' 'tidyr'
# All declared Imports should be used.


ignore_unused_imports <- function() {
# Removes NOTE because of packages needed for building vignette: "Contribute to ..."
rmarkdown::html_vignette
knitr::opts_chunk
NVIrpackages::NVIpackages
# R.rsp is used when adding the pdf reference manual as a vignette
R.rsp::rfile
}
32 changes: 21 additions & 11 deletions R/read_eos_data.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
#' @title Read EOS data from RaData
#' @description Reads EOS data from RaData. Includes historical data if these exists.
#' It is possible to limit the data to one or more years.
#' @details read_eos_data uses \code{data.table::fread} to read the data with the
#' settings \code{showProgress = FALSE} and \code{data.table = FALSE}. Other
#' arguments can be passed to \code{data.table::fread} if necessary.
#' @details read_eos_data uses
#' \ifelse{html}{\code{\link[data.table:fread]{data.table::fread}}}{\code{data.table::fread}}
#' to read the data with the settings \code{showProgress = FALSE} and
#' \code{data.table = FALSE}. Other arguments can be passed to
#' \ifelse{html}{\code{\link[data.table:fread]{data.table::fread}}}{\code{data.table::fread}}
#' if necessary.
#'
#' The eos_table name is the same name as the name as in the EOS data base.
#' The eos_table name is the same name as the name as in the EOS data base.
#'
#' @param from_path Path for raw data from eos_data
#' @param eos_table The name of the table with eos raw data.
#' @param year The years to be included in the result. Can be both numeric
#' @param from_path [\code{character(1)}]\cr
#' Path for raw data from eos_data.
#' @param eos_table [\code{character(1)}]\cr
#' The name of the table with eos raw data.
#' @param year [\code{character} | \code{numeric}]\cr
#' The years to be included in the result. Can be both numeric
#' or character. Defaults to \code{NULL}, i.e. no selection.
#' @param colClasses The class of the columns, as in utils::read.table, Defaults to
#' \code{"character"}.
#' @param encoding The encoding. Defaults to \code{"UTF-8"}.
#' @param \dots Other arguments to be passed to \code{data.table::fread}.
#' @param colClasses [\code{character}]\cr
#' The class of the columns, as in
#' \ifelse{html}{\code{\link[utils:read.table]{utils::read.table}}}{\code{utils::read.table}}.
#' Defaults to \code{"character"}.
#' @param encoding [\code{character(1)}]\cr
#' The encoding, one of c("UTF-8", "latin1"). Defaults to \code{"UTF-8"}.
#' @param \dots Other arguments to be passed to
#' \ifelse{html}{\code{\link[data.table:fread]{data.table::fread}}}{\code{data.table::fread}}.
#'
#' @return A data frame with data from EOS.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/standardize_eos_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ standardize_eos_data <- function(data,
# Object to store check-results
checks <- checkmate::makeAssertCollection()
# Perform checks
checkmate::assert_data_frame(data)
checkmate::assert_data_frame(data, add = checks)
checkmate::assert_character(dbsource, len = 1, min.chars = 1, add = checks)
checkmate::assert_data_frame(standards, null.ok = TRUE, add = checks)
checkmate::assert_flag(standardize_colnames, add = checks)
Expand Down
4 changes: 3 additions & 1 deletion data-raw/generate_PJS_code_description_colname.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# GENERATE rda-file with the corresponding standard colnames for description to PJS code variables

# GENERATE DATA ----
PJS_code_description_colname <- as.data.frame(matrix(rbind(c("ansvarlig_seksjon", "seksjon", "ansvarlig_seksjon_navn"),
PJS_code_description_colname <- as.data.frame(matrix(rbind(c("sakskonkl_kjennelsekode", "kjennelse", "sakskonkl_kjennelse"),
c("sakskonkl_analyttkode", "analytt", "sakskonkl_analytt"),
c("ansvarlig_seksjon", "seksjon", "ansvarlig_seksjon_navn"),
c("utf_seksjon", "seksjon", "utforende_seksjon_navn"),
c("hensiktkode", "hensikt", "hensikt"),
c("utbruddnr", "utbrudd", "utbrudd"),
Expand Down
Binary file modified data/PJS_code_description_colname.rda
Binary file not shown.
8 changes: 5 additions & 3 deletions man/add_PJS_code_description.Rd

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

Loading

0 comments on commit 917b724

Please sign in to comment.