Skip to content

Commit

Permalink
Merge pull request #58 from NorwegianVeterinaryInstitute/dev
Browse files Browse the repository at this point in the history
NVIdb v0.11.2
  • Loading branch information
PetterHopp authored Apr 5, 2024
2 parents b8714c0 + ebab622 commit 9ee81a0
Show file tree
Hide file tree
Showing 34 changed files with 999 additions and 362 deletions.
6 changes: 3 additions & 3 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.11.1
Date: 2024-02-05
Version: 0.11.2
Date: 2024-04-05
Authors@R:
c(person(given = "Petter",
family = "Hopp",
Expand Down Expand Up @@ -63,7 +63,7 @@ LazyData: true
Encoding: UTF-8
Language: en-GB
Roxygen: list(markdown = FALSE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder:
knitr,
R.rsp
23 changes: 21 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
NVIdb 0.11.2 - (2024-04-05)
----------------------------------------

Bug fixes:

- `retrieve_PJSdata` now accepts input for `selection_parameters` that includes `FUN` and `selection_statement`.

- `set_disease_parameters` now accepts input for `selection_parameters` that includes `FUN`.


BREAKING CHANGES:

- For `retrieve_PJSdata`, the arguments `FUN` and `select_statement` are deprecated. These should instead be included in the list input to `selection_parameters`. See NVIdb-deprecated (help("NVIdb-deprecated")).

- The wrapper functions `login_EOS`, `login_by_input_EOS`, and `login_by_credentials_EOS` are deprecated. Use the corresponding login-functions with the argument `dbservice` = "EOS" instead. See NVIdb-deprecated (help("NVIdb-deprecated")).

- The wrapper function `set_credentials_EOS` is deprecated. Use `set_credentials("EOS")` instead. See NVIdb-deprecated (help("NVIdb-deprecated")).


NVIdb 0.11.1 - (2024-02-05)
----------------------------------------

Expand Down Expand Up @@ -41,9 +60,9 @@ Other changes:

BREAKING CHANGES:

- In `set_disease_parameters` the arguments `missing_art` and `file` is deprecated. These are replaced by `include_missing_art` and `selection_parameters`, respectively. If using the old arguments, the input will be transferred to the new arguments.
- In `set_disease_parameters` the arguments `missing_art` and `file` is deprecated. These are replaced by `include_missing_art` and `selection_parameters`, respectively. If using the old arguments, the input will be transferred to the new arguments. See NVIdb-deprecated (help("NVIdb-deprecated")).

- `set_PAT`, `get_PAT`, and `remove_PAT` was deprecated.These should be replaced by corresponding functions in package `gitcreds`.
- `set_PAT`, `get_PAT`, and `remove_PAT` was deprecated.These should be replaced by corresponding functions in package `gitcreds`. See NVIdb-deprecated (help("NVIdb-deprecated")).


NVIdb 0.10.1 - (2023-05-31)
Expand Down
39 changes: 33 additions & 6 deletions R/NVIdb-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,39 @@
#' @details \code{add_produsent} was deprecated from v0.8.0 released 2022-08-25
#' as other properties
#' than 'gjeldende_prodnr8' could not be included without breaking backward
#' compatibility. Use \code{add_produsent_properties} instead and ensure
#' compatibility. Use \code{\link{add_produsent_properties}} instead and ensure
#' to set the parameter \code{impute_old_when_missing = TRUE} when translating
#' from "prodnr8" to "gjeldende_prodnr8" and set the parameter
#' \code{impute_old_when_missing = FALSE} when translating from "prodnr8" to
#' other properties.
#'
#' \code{set_PAT}, \code{get_PAT}, and \code{remove_PAT} was deprecated from
#' v0.11.0 released 2023-09-22. The functions were never taken into use.
#' v0.11.0 released 2024-01-24. The functions were never taken into use.
#' Functions from the much better package \code{gitcreds} should be used instead.
#'
#' The arguments \code{missing_art} and \code{file} in \code{set_disease_parameters}
#' was deprecated from v0.11.0 released 2024-01-24. These arguments are
#' replaced by the more meaningful \code{include_missing_art} and
#' \code{selection_parameters}, respectively. If using the old arguments,
#' the input will be transferred to the new arguments.
#'
#' \code{login_EOS}, \code{login_by_input_EOS}, and \code{login_by_credentials_EOS}
#' was deprecated from v0.##.# released 2024-##-##. The functions were rarely
#' used and are unnecessary wrappers around the login-functions. The
#' login-functions with the argument \code{dbservice} = "EOS" should be used
#' instead, see \code{\link{login}}.
#'
#' \code{set_credentials_EOS} was deprecated from v0.##.# released 2024-##-##.
#' The function was rarely used and is an unnecessary wrapper around
#' \code{set_credentials}. \code{\link{set_credentials}} with the argument
#' \code{dbservice} = "EOS" should be used instead.
#'
#' The arguments \code{FUN} and \code{selection_statement} in \code{retrieve_PJSdata}
#' was deprecated from v0.##.# released 2024-##-##. These arguments should
#' instead be included in the list input to \code{selection_parameters}. If
#' using the old arguments, the input will be transferred to
#' \code{selection_parameters}.
#'
#' @param \dots (arguments)
#' @return (results)
#' @name NVIdb-deprecated
Expand All @@ -25,9 +48,13 @@
#'
#' @examples
#' \dontrun{
#' add_produsent(...) ### -- use \code{\link{add_produsent_properties}} instead.
#' set_PAT(...) ### -- use \code{\link{gitcreds::gitcreds_set}} instead.
#' get_PAT(...) ### -- use \code{\link{gitcreds::gitcreds_get}} instead.
#' remove_PAT(...) ### -- use \code{\link{gitcreds::gitcreds_delete}} instead.
#' add_produsent(...) ### -- use add_produsent_properties() instead.
#' set_PAT(...) ### -- use gitcreds::gitcreds_set() instead.
#' get_PAT(...) ### -- use gitcreds::gitcreds_get() instead.
#' remove_PAT(...) ### -- use gitcreds::gitcreds_delete() instead.
#' login_EOS(...) ### -- use login("EOS") instead.
#' login_by_input_EOS(...) ### -- use login_by_input("EOS") instead.
#' login_by_credentials_EOS(...) ### -- use login_by_credentials("EOS") instead.
#' set_credentials_EOS(...) ### -- use set_credentials("EOS") instead.
#' }
NULL
122 changes: 51 additions & 71 deletions R/login.R
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
#' @title Log in to data base services
#' @description Log in to NVI's data base services, in particular journal_rapp/PJS and EOS.
#' @description Log in to NVI's data base services, in particular journal_rapp/PJS.
#' @details The NVI has access to several database services. These functions log
#' in to such services. The functions provides methods to either log in using
#' credentials set in the user profile by \code{\link{set_credentials}} or use
#' input windows for username and password. Thereby the hard coding of
#' username and password can be avoided.
#'
#' \code{login} is general functions where all necessary specifications like
#' server name and database name of the database must be input. The database
#' provider can give information on what specifications that has to be used.
#' This can be used to log in to many different databases. In the case that
#' one login to a database service for which the connection parameters have
#' been predefined (i.e. PJS, EOS, sea_sites and Fallvilt), it will be sufficient
#' to provide the parameter \code{dbservice =}.
#' \code{login} is a general function for connecting to databases, where all
#' necessary connection parameters like server name and database name of the
#' database must be input. The database provider can inform you on the
#' connection parameters for their database. In the case that one login to
#' a database service for which the connection parameters have been predefined
#' (i.e. PJS, EOS, sea_sites, Fallvilt and Dataflex), it will be sufficient
#' to provide the parameter \code{dbservice}, for example \code{dbservice} =
#' "EOS".
#'
#' Depending on whether username and password have been saved in the users
#' profile at the current computer or not, the user is asked to input credentials.
#'
#' \code{login_by_input} is general functions where all necessary
#' specifications like server name and database name of the database must be
#' input. In the case that one login to a database service for which the
#' connection parameters have been predefined (i.e. PJS, EOS, sea_sites and
#' Fallvilt), it will be sufficient to provide the parameter \code{dbservice =}.
#' The user is always asked to input username and password.
#' \code{login_by_input} is a general function for connecting to databases,
#' where all necessary connection parameters like server name and database name
#' of the database must be input. The database provider can inform you on the
#' connection parameters for their database. In the case that one login to
#' a database service for which the connection parameters have been predefined
#' (i.e. PJS, EOS, sea_sites, Fallvilt and Dataflex), it will be sufficient
#' to provide the parameter \code{dbservice}. The user is always asked to input
#' username and password.
#'
#' \code{login_by_credentials} is general functions where all necessary
#' specifications like server name and database name of the database must be
#' input. In the case that one login to a database service for which the
#' connection parameters have been predefined (i.e. PJS, EOS, sea_sites and
#' Fallvilt), it will be sufficient to provide the parameter \code{dbservice =}.
#' The user is never asked for username and password, and the function can
#' only be used when the credentials previously have been set in the user's
#' profile at the current computer.
#' \code{login_by_credentials} is a general function for connecting to databases,
#' where all necessary connection parameters like server name and database name
#' of the database must be input. The database provider can inform you on the
#' connection parameters for their database. In the case that one login to
#' a database service for which the connection parameters have been predefined
#' (i.e. PJS, EOS, sea_sites, Fallvilt and Dataflex), it will be sufficient
#' to provide the parameter \code{dbservice}. The user is never asked for username
#' and password, and the function can only be used when the credentials previously
#' have been set in the user's profile at the current computer.
#'
#' \code{login_PJS}, \code{login_by_input_PJS}, and \code{login_by_credentials_PJS}
#' are wrappers for the functions above where the specifications for the
#' database journal_rapp/PJS have been preset. The user only need to input
#' database journal_rapp/PJS have been pre set. The user only need to input
#' username and password. In the case that the username and password for
#' journal_rapp/PJS have been stored in the user profile at the current
#' computer, the user is automatically logged in to journal_rapp. If the
#' password is no longer valid, an error occur. If so, the user must update
#' the username and password by \code{\link{set_credentials_PJS}}.
#'
#' \code{login_EOS}, \code{login_by_input_EOS}, and \code{login_by_credentials_EOS}
#' are wrappers for the functions above where the specifications for the
#' database EOS have been preset. The user only need to input username and
#' password or if the credentials are saved in the users profile by
#' \code{\link{set_credentials_EOS}}, no input is needed.
#' The wrapper functions \code{login_EOS}, \code{login_by_input_EOS}, and
#' \code{login_by_credentials_EOS} have been deprecated.
#'
#' The login functions returns an open ODBC-channel to the database service.
#' The database can then be queried by using functions in the package used for
Expand All @@ -55,31 +56,39 @@
#' \code{RODBC} for "SQL server" and \code{RPostgreSQL} for "PostgreSQL".
#'
#' When the session is finished, the script shall close the ODBC-channel by
#' \code{odbcClose("myodbcchannel")} or \code{odbcCloseAll}.
#' \code{odbcClose("myodbcchannel")} or \code{odbcCloseAll} when using RODBC.
#'
#' @param dbservice Name of the database service, for example "PJS" or "EOS".
#' @param dbservice [\code{character(1)}]\cr
#' Name of the database service, for example "PJS" or "EOS".
#' For database services where one don't use the premade wrappers, the name
#' can be chosen freely, but must be the same as used in \code{\link{set_credentials}}.
#' @param dbdriver Name of database engine.
#' @param db Name of database.
#' @param dbserver Name of database server.
#' @param dbport Port.
#' @param dbprotocol Protocol to be used.
#' @param dbinterface The R-package that is used for interface towards the data
#' base.
#' @param dbtext used in login with input. Gives the possibility of showing
#' another name than the dbservice in the windows asking for username and
#' password.
#' @param dbdriver [\code{character(1)}]\cr
#' Name of database engine. Defaults to \code{NULL}.
#' @param db [\code{character(1)}]\cr
#' Name of database. Defaults to \code{NULL}.
#' @param dbserver [\code{character(1)}]\cr
#' Name of database server. Defaults to \code{NULL}.
#' @param dbport [\code{character(1)}]\cr
#' Port. Defaults to \code{NULL}.
#' @param dbprotocol [\code{character(1)}]\cr
#' Protocol to be used. Defaults to \code{NULL}.
#' @param dbinterface [\code{character(1)}]\cr
#' The R-package that is used for interface towards the data
#' base. Defaults to \code{NULL}.
#' @param dbtext [\code{character(1)}]\cr
#' Gives the possibility of showing another name than the dbservice
#' in the windows asking for username and password when using
#' \code{login_by_input}. Defaults to \code{NULL}.
#' @param \dots Other arguments to be passed from the wrappers to
#' login_by_credentials or login_by_input
#' \code{login_by_credentials} or \code{login_by_input}.
#' @return An open ODBC-channel to the database service.
#' @family Log in functions
#' @seealso \code{\link{set_credentials}}
#' @author Petter Hopp Petter.Hopp@@vetinst.no
#' @export
#' @examples
#' \dontrun{
#' require(RODBC)
#' library(RODBC)
#' journal_rapp <- login_PJS()
#' # Reads hensiktregistret from PJS
#' hensikter <- sqlQuery(journal_rapp,
Expand Down Expand Up @@ -240,32 +249,3 @@ login_PJS <- function(dbinterface = NULL, ...) {
login_by_input(dbservice, dbinterface = dbinterface, ...)
}
}


#' @export
#' @rdname login

login_EOS <- function(dbinterface = NULL, ...) {

# ARGUMENT CHECKING ----
# Object to store check-results
checks <- checkmate::makeAssertCollection()

# dbinterface
checkmate::assert_choice(dbinterface, choices = c("odbc", "RPostgreSQL", "RODBC"), null.ok = TRUE, add = checks)

# Report check-results
checkmate::reportAssertions(checks)

# Set service to EOS
dbservice <- "EOS"

# Use check for saved credentials to chose between login_by_input and login_by_credentials
if (isTRUE(NVIcheckmate::check_credentials(dbservice))) {
# If credentials are saved for the user profile
login_by_credentials(dbservice, dbinterface = dbinterface, ...)
} else {
# If credentials are missing from the user profile
login_by_input(dbservice, dbinterface = dbinterface, ...)
}
}
Loading

0 comments on commit 9ee81a0

Please sign in to comment.