From 5df289a884e662657e5d7e360571af41c8c1db72 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 10:18:01 +0100 Subject: [PATCH 01/34] Bump dev version number --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 93b56d6..cd44eb4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: watina Title: Querying And Processing Data From The INBO Watina Database -Version: 0.3.0 +Version: 0.3.0.9000 Description: The R-package watina contains functions to query and process data from the Watina database at the Research Institute for Nature and Forest (INBO). This database primarily provides From 1f342b2e5a310a23d6a146d060449d7b037480ec Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 18 Jun 2020 08:30:28 +0200 Subject: [PATCH 02/34] warn_xy_duplicates(): cosmetic update of message --- R/sf.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sf.R b/R/sf.R index cef60a8..0180bdc 100644 --- a/R/sf.R +++ b/R/sf.R @@ -118,7 +118,7 @@ warn_xy_duplicates <- function(x, y) { warning("1 coordinate pair occurs more than once.") } else { warning(n_duplicated, - " different coordinate pairs occur more than once.") + " different coordinate pairs occur more than once.\n") } } From c96421e095745e32733302815538848c16f85b25 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 18 Jun 2020 08:54:10 +0200 Subject: [PATCH 03/34] warn_xy_duplicates(): don't error on empty input * This is especially useful after masking: when nothing comes out of the spatial join, this internal function that checks for duplicate coordinates should not error. --- R/sf.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/sf.R b/R/sf.R index 0180bdc..d79da8a 100644 --- a/R/sf.R +++ b/R/sf.R @@ -105,7 +105,6 @@ warn_xy_duplicates <- function(x, y) { assert_that(is.numeric(x)) assert_that(is.numeric(y)) assert_that(all.equal(length(x), length(y))) - assert_that(length(x) > 0) n_duplicated <- data.frame(x = x, y = y) %>% From b048f1b89cbe5fbaa3044988b5f7fc0a3d402b3a Mon Sep 17 00:00:00 2001 From: florisvdh Date: Fri, 8 Jan 2021 16:55:14 +0100 Subject: [PATCH 04/34] Documentation: incoming upstream changes --- DESCRIPTION | 2 +- man/collect.Rd | 4 +++- man/convertdf_enc.Rd | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cd44eb4..816e304 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,5 +40,5 @@ Remotes: florisvdh/dbplyr@dbplyr_with_pivot_wider LazyData: true Encoding: UTF-8 -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 VignetteBuilder: knitr diff --git a/man/collect.Rd b/man/collect.Rd index 24da75c..7c69f19 100644 --- a/man/collect.Rd +++ b/man/collect.Rd @@ -8,7 +8,9 @@ if OS is Windows} collect(x) } \arguments{ -\item{x}{A tbl} +\item{x}{A data frame, data frame extension (e.g. a tibble), or a lazy +data frame (e.g. from dbplyr or dtplyr). See \emph{Methods}, below, for more +details.} } \description{ Works as a simple \code{\link[dplyr:compute]{collect()}}, on which it is diff --git a/man/convertdf_enc.Rd b/man/convertdf_enc.Rd index 95dcba1..345d5ad 100644 --- a/man/convertdf_enc.Rd +++ b/man/convertdf_enc.Rd @@ -17,7 +17,8 @@ class} \item{sub}{character string. If not \code{NA} it is used to replace any non-convertible bytes in the input. (This would normally be a single character, but can be more.) If \code{"byte"}, the indication is - \code{""} with the hex code of the byte.} + \code{""} with the hex code of the byte. If \code{"Unicode"} + and converting from UTF-8, the Unicode point in the form \code{""}.} } \value{ The original object, with character variables (and levels of From e66e58ff5cd467135c395bad69fb0edf0423e085 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 09:45:07 +0100 Subject: [PATCH 05/34] Incorporate internal function db_pivot_wider for the time being * It appears that another pivot_wider function is being prepared at dbplyr, but in the meantime I wanted to prevent the need for my fork of dbplyr, that took the pivot_wider branch of Edgar Ruiz (who proposed the function) and brought it up to date with dbplyr's master at times. By incorporating the function, the watina package can just work with dbplyr from CRAN and still use the functionality. All credits for db_pivot_wider() go to Edgar Ruiz. --- DESCRIPTION | 7 ++-- NAMESPACE | 9 ++++- R/db_pivot_wider.R | 82 ++++++++++++++++++++++++++++++++++++++++++++++ R/get.R | 2 -- 4 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 R/db_pivot_wider.R diff --git a/DESCRIPTION b/DESCRIPTION index 816e304..668826a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,10 +34,11 @@ Imports: tidyr Suggests: knitr, - rmarkdown + purrr, + rmarkdown, + tidyselect Remotes: - inbo/inbodb, - florisvdh/dbplyr@dbplyr_with_pivot_wider + inbo/inbodb LazyData: true Encoding: UTF-8 RoxygenNote: 7.1.1 diff --git a/NAMESPACE b/NAMESPACE index 041112f..3908b35 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,7 +23,6 @@ importFrom(assertthat,is.flag) importFrom(assertthat,is.number) importFrom(assertthat,is.string) importFrom(assertthat,noNA) -importFrom(dbplyr,db_pivot_wider) importFrom(dplyr,"%>%") importFrom(dplyr,anti_join) importFrom(dplyr,arrange) @@ -68,6 +67,14 @@ importFrom(lubridate,now) importFrom(lubridate,today) importFrom(lubridate,year) importFrom(rlang,.data) +importFrom(rlang,enquo) +importFrom(rlang,enquos) +importFrom(rlang,expr) +importFrom(rlang,flatten) +importFrom(rlang,quo_get_expr) +importFrom(rlang,set_names) +importFrom(rlang,sym) +importFrom(rlang,syms) importFrom(sf,st_as_sf) importFrom(sf,st_buffer) importFrom(sf,st_coordinates) diff --git a/R/db_pivot_wider.R b/R/db_pivot_wider.R new file mode 100644 index 0000000..2921e77 --- /dev/null +++ b/R/db_pivot_wider.R @@ -0,0 +1,82 @@ +# NOTE: all credits for this db_pivot_wider function go to Edgar Ruiz. +# He made a PR where this function was proposed to incorporate in dbplyr: +# https://github.com/tidyverse/dbplyr/pull/344 +# The code below is a copy and the terms of its original code source apply. +# Minor modifications were made in the approach to import rlang functions and to +# avoid global variables. + +#' @importFrom rlang +#' .data +#' sym +#' syms +#' set_names +#' flatten +#' enquo +#' enquos +#' quo_get_expr +#' expr +#' @keywords internal +db_pivot_wider <- function(data, + id_cols = NULL, + names_from = .data$name, + names_prefix = "", + names_sep = NULL, + names_repair = NULL, + values_from = .data$value, + values_fill = NULL, + values_fn = NULL, + spec = NULL) { + if (!requireNamespace("tidyselect", quietly = TRUE)) { + stop("Package \"tidyselect\" is needed when using this function. ", + "Please install it.", + call. = FALSE) + } + if (!requireNamespace("purrr", quietly = TRUE)) { + stop("Package \"purrr\" is needed when using this function. ", + "Please install it.", + call. = FALSE) + } + check_null_pivot_args( + id_cols = !!id_cols, names_sep = !!names_sep, + names_repair = !!names_repair, values_fill = !!values_fill, + values_fn = !!values_fn, spec = !!spec + ) + cn <- colnames(data) + names_from <- tidyselect::vars_select(cn, !!enquo(names_from)) + values_from <- tidyselect::vars_select(cn, !!enquo(values_from)) + pl <- c(values_from, names_from) + kp <- cn[!(cn %in% pl)] + headers <- pull(summarise(group_by(data, !!sym(names_from)))) + mt <- purrr::map( + headers, + ~ { + header <- .x + purrr::map( + values_from, + ~ expr(max(ifelse(!!sym(names_from) == !!header, !!sym(.x), NA), na.rm = TRUE)) + ) + } + ) + fmt <- flatten(mt) + if (length(values_from) > 1) { + vp <- paste0(values_from, "_") + } else { + vp <- "" + } + hn <- purrr::map(headers, ~ paste0(vp, names_prefix, .x)) + rhn <- purrr::reduce(hn, c) + nmt <- set_names(fmt, rhn) + grps <- group_by(data, !!!syms(kp)) + summarise(grps, !!!nmt) +} + +check_null_pivot_args <- function(..., msg = "The `{arg}` argument is not supported for remote back-ends") { + vars <- enquos(...) + purrr::imap( + vars, + ~ assert_that( + is.null(quo_get_expr(.x)), + msg = sub("\\{arg\\}", .y, msg) + ) + ) +} diff --git a/R/get.R b/R/get.R index 62748ca..39d8b95 100644 --- a/R/get.R +++ b/R/get.R @@ -1029,8 +1029,6 @@ get_xg3 <- function(locs, #' day #' month #' year -#' @importFrom dbplyr -#' db_pivot_wider #' @importFrom dplyr #' %>% #' copy_to From 90f91d6baab66342cd1612f3beb929fd02ff38a9 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 10:15:54 +0100 Subject: [PATCH 06/34] Update .travis.yml: use Bionic, install libs --- .travis.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e8955c..8cc4803 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,26 @@ +addons: + apt: + sources: + - sourceline: 'ppa:ubuntugis/ubuntugis-unstable' + packages: + - libudunits2-dev + - libgdal-dev + - libproj-dev + - libgeos-dev + - libfftw3-dev + - libfribidi-dev + language: r + +dist: bionic + cache: packages r_packages: - pkgdown -r_github_packages: - - inbo/inborutils - -apt_packages: - - libudunits2-dev # For inborutils - - libgdal1-dev # For inborutils - - libfftw3-dev # For watina - after_success: - - R CMD INSTALL . # Install the package to build vignettes + - R CMD INSTALL . - Rscript -e "pkgdown::build_site(preview = FALSE)" deploy: From 19e0b2b35e57b3b10d397d357b1ff09a7f1fe457 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 16:59:54 +0100 Subject: [PATCH 07/34] selectlocs_xxx(): fix #72 = avoid .data inside nesting() --- R/selectlocs.R | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/R/selectlocs.R b/R/selectlocs.R index 052c4fd..6d0eefd 100644 --- a/R/selectlocs.R +++ b/R/selectlocs.R @@ -553,10 +553,11 @@ selectlocs_xg3 <- function(data, filter(str_detect(.data$statistic, "ser_")), by = c("xg3_variable", "statistic")) %>% - complete(.data$loc_code, nesting(.data$xg3_variable, - .data$statistic, - .data$criterion, - .data$direction)) %>% + complete(.data$loc_code, with(.data, + nesting(xg3_variable, + statistic, + criterion, + direction))) %>% mutate(cond_met = ifelse(.data$direction == "min", .data$value >= .data$criterion, ifelse(.data$direction == "max", .data$value <= .data$criterion, @@ -1225,10 +1226,11 @@ selectlocs <- function(data, right_join(conditions, by = c("variable", "statistic")) %>% - complete(.data$loc_code, nesting(.data$variable, - .data$statistic, - .data$criterion, - .data$direction)) %>% + complete(.data$loc_code, with(.data, + nesting(variable, + statistic, + criterion, + direction))) %>% mutate(cond_met = ifelse(.data$direction == "min", .data$value >= .data$criterion, ifelse(.data$direction == "max", .data$value <= .data$criterion, From b7b6ca922eb00cf7ab8b1ac6690bb6b8179ba973 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 17:19:40 +0100 Subject: [PATCH 08/34] get_chem(): only arrange() upon collecting * See https://dbplyr.tidyverse.org/news/index.html#sql-generation: bullet on ORDER BY in subqueries. This also means that, if you like to have the printed output of a lazy query in a sorted manner, you need to add '%>% arrange()' yourself! --- R/get.R | 20 ++++++++++++++++---- man/get_chem.Rd | 10 ++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/R/get.R b/R/get.R index 39d8b95..7e0e2ad 100644 --- a/R/get.R +++ b/R/get.R @@ -906,6 +906,18 @@ get_xg3 <- function(locs, #' #' TO BE ADDED: What is electroneutrality and why is it used as a criterion? #' +#' @md +#' +#' @note +#' Up to and including `watina 0.3.0`, the result was sorted according to +#' `loc_code`, `date` and `chem_variable`, both for the lazy query and the +#' collected result. +#' Later versions avoid sorting in case of a lazy result, because +#' otherwise, when using the result inside another lazy query, this led to +#' 'ORDER BY' constructs in SQL subqueries, which must be avoided. +#' If you like to print the lazy object in a sorted manner, you must add +#' `%>% arrange(...)` yourself. +#' #' @param startdate First date of the timeframe, as a string. #' The string must use a formatting of the order 'day month year', #' i.e. a format which can be interpreted by \code{\link[lubridate:ymd]{dmy}}. @@ -1258,14 +1270,14 @@ get_chem <- function(locs, .data$unit)) ) %>% select(-contains("value_"), -.data$provide_eq_unit) %>% - mutate(unit = ifelse(.data$unit == "/", NA, .data$unit)) %>% - arrange(.data$loc_code, - .data$date, - .data$chem_variable) + mutate(unit = ifelse(.data$unit == "/", NA, .data$unit)) if (collect) { chem <- chem %>% + arrange(.data$loc_code, + .data$date, + .data$chem_variable) %>% collect } diff --git a/man/get_chem.Rd b/man/get_chem.Rd index c841e2a..5d0eb70 100644 --- a/man/get_chem.Rd +++ b/man/get_chem.Rd @@ -136,6 +136,16 @@ To retrieve all data from all water samples, use \code{en_range = c(-1, 1)}. TO BE ADDED: What is electroneutrality and why is it used as a criterion? } +\note{ +Up to and including \verb{watina 0.3.0}, the result was sorted according to +\code{loc_code}, \code{date} and \code{chem_variable}, both for the lazy query and the +collected result. +Later versions avoid sorting in case of a lazy result, because +otherwise, when using the result inside another lazy query, this led to +'ORDER BY' constructs in SQL subqueries, which must be avoided. +If you like to print the lazy object in a sorted manner, you must add +\verb{\%>\% arrange(...)} yourself. +} \examples{ \dontrun{ watina <- connect_watina() From 260c95926b1c1562d6d648845ada5d279c560adb Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 18:02:58 +0100 Subject: [PATCH 09/34] get_locs(): only arrange() upon collecting * See https://dbplyr.tidyverse.org/news/index.html#sql-generation: bullet on ORDER BY in subqueries. This also means that, if you like to have the printed output of a lazy query in a sorted manner, you need to add '%>% arrange()' yourself! --- R/get.R | 27 ++++++++++++++------------- man/get_locs.Rd | 10 ++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/R/get.R b/R/get.R index 7e0e2ad..f34c271 100644 --- a/R/get.R +++ b/R/get.R @@ -139,6 +139,18 @@ #' retained observation well. #' It is ignored if \code{obswells = TRUE}. #' +#' @md +#' +#' @note +#' Up to and including `watina 0.3.0`, the result was sorted according to +#' `area_code`, `loc_code` and (for observation wells) `obswell_rank`, +#' both for the lazy query and the collected result. +#' Later versions avoid sorting in case of a lazy result, because +#' otherwise, when using the result inside another lazy query, this led to +#' 'ORDER BY' constructs in SQL subqueries, which must be avoided. +#' If you like to print the lazy object in a sorted manner, you must add +#' `%>% arrange(...)` yourself. +#' #' @param mask An optional geospatial filter of class \code{sf}. #' If provided, only locations that intersect with \code{mask} will be returned, #' with the value of \code{buffer} taken into account. @@ -455,10 +467,7 @@ get_locs <- function(con, measuringref_ost = .data$ReferentieNiveauTAW, .data$tubelength, .data$filterlength, - .data$filterdepth) %>% - arrange(.data$area_code, - .data$loc_code, - .data$obswell_rank) + .data$filterdepth) if (filterdepth_guess) { locs <- @@ -493,12 +502,6 @@ get_locs <- function(con, ) } - locs <- - locs %>% - arrange(.data$area_code, - .data$loc_code, - .data$obswell_rank) - if (!obswells) { locs <- @@ -597,9 +600,7 @@ get_locs <- function(con, -.data$obswell_count, -.data$obswell_maxrank, -.data$obswell_maxrank_fd, - -.data$obswell_maxrank_sso) %>% - arrange(.data$area_code, - .data$loc_code) + -.data$obswell_maxrank_sso) } if (!is.null(mask)) { diff --git a/man/get_locs.Rd b/man/get_locs.Rd index 23a984a..db0351c 100644 --- a/man/get_locs.Rd +++ b/man/get_locs.Rd @@ -222,6 +222,16 @@ Here, the term 'observation well' is used to refer to a fixed installed device in the field (groundwater piezometer, surface water level measurement device). } +\note{ +Up to and including \verb{watina 0.3.0}, the result was sorted according to +\code{area_code}, \code{loc_code} and (for observation wells) \code{obswell_rank}, +both for the lazy query and the collected result. +Later versions avoid sorting in case of a lazy result, because +otherwise, when using the result inside another lazy query, this led to +'ORDER BY' constructs in SQL subqueries, which must be avoided. +If you like to print the lazy object in a sorted manner, you must add +\verb{\%>\% arrange(...)} yourself. +} \examples{ \dontrun{ watina <- connect_watina() From 94b8a54f86855e00d8803ec20f5743a823bee356 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 18:07:15 +0100 Subject: [PATCH 10/34] get_xg3(): only arrange() upon collecting * See https://dbplyr.tidyverse.org/news/index.html#sql-generation: bullet on ORDER BY in subqueries. This also means that, if you like to have the printed output of a lazy query in a sorted manner, you need to add '%>% arrange()' yourself! --- R/get.R | 18 +++++++++++++++--- man/get_xg3.Rd | 10 ++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/R/get.R b/R/get.R index f34c271..72acba4 100644 --- a/R/get.R +++ b/R/get.R @@ -702,6 +702,18 @@ get_locs <- function(con, #' Why truncate, and why truncate by default? #' When to choose which \code{vert_crs}?) #' +#' @md +#' +#' @note +#' Up to and including `watina 0.3.0`, the result was sorted according to +#' `loc_code` and `hydroyear`, both for the lazy query and the +#' collected result. +#' Later versions avoid sorting in case of a lazy result, because +#' otherwise, when using the result inside another lazy query, this led to +#' 'ORDER BY' constructs in SQL subqueries, which must be avoided. +#' If you like to print the lazy object in a sorted manner, you must add +#' `%>% arrange(...)` yourself. +#' #' @param locs A \code{tbl_lazy} object or a dataframe, with at least a column #' \code{loc_code} that defines the locations for which values are to be #' returned. @@ -854,13 +866,13 @@ get_xg3 <- function(locs, local = xg3 %>% select(-contains("ost")), ostend = xg3 %>% select(-contains("lcl")), both = xg3 - ) %>% - arrange(.data$loc_code, - .data$hydroyear) + ) if (collect) { xg3 <- xg3 %>% + arrange(.data$loc_code, + .data$hydroyear) %>% collect } diff --git a/man/get_xg3.Rd b/man/get_xg3.Rd index 6e81edb..f177a3d 100644 --- a/man/get_xg3.Rd +++ b/man/get_xg3.Rd @@ -86,6 +86,16 @@ Currently, non-truncated values are returned, with usage of estimated values. Why truncate, and why truncate by default? When to choose which \code{vert_crs}?) } +\note{ +Up to and including \verb{watina 0.3.0}, the result was sorted according to +\code{loc_code} and \code{hydroyear}, both for the lazy query and the +collected result. +Later versions avoid sorting in case of a lazy result, because +otherwise, when using the result inside another lazy query, this led to +'ORDER BY' constructs in SQL subqueries, which must be avoided. +If you like to print the lazy object in a sorted manner, you must add +\verb{\%>\% arrange(...)} yourself. +} \examples{ \dontrun{ watina <- connect_watina() From 88a9cf44f2606ca261be8a9faba7c52ac8986bb2 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 19:38:51 +0100 Subject: [PATCH 11/34] Examples: sort lazy results --- R/eval.R | 6 +++--- R/extract.R | 2 +- R/get.R | 36 ++++++++++++++++++++++++------------ R/selectlocs.R | 4 ++-- man/eval_chem.Rd | 2 +- man/eval_xg3_avail.Rd | 2 +- man/eval_xg3_series.Rd | 2 +- man/extract_xg3_series.Rd | 2 +- man/get_chem.Rd | 14 ++++++++++---- man/get_locs.Rd | 3 ++- man/get_xg3.Rd | 19 ++++++++++++------- man/selectlocs_chem.Rd | 2 +- man/selectlocs_xg3.Rd | 2 +- 13 files changed, 60 insertions(+), 36 deletions(-) diff --git a/R/eval.R b/R/eval.R index f8060a3..6b806fc 100644 --- a/R/eval.R +++ b/R/eval.R @@ -33,7 +33,7 @@ #' mydata <- #' mylocs %>% #' get_xg3(watina, 2014) -#' mydata +#' mydata %>% arrange(loc_code, hydroyear) #' eval_xg3_avail(mydata, #' xg3_type = c("L", "V")) #' # Disconnect: @@ -340,7 +340,7 @@ qualify_xg3 <- function(data, #' mydata <- #' mylocs %>% #' get_xg3(watina, 1900) -#' mydata +#' mydata %>% arrange(loc_code, hydroyear) #' mydata %>% #' eval_xg3_series(xg3_type = c("L", "V"), #' max_gap = 2, @@ -591,7 +591,7 @@ eval_xg3_series <- function(data, #' mydata <- #' mylocs %>% #' get_chem(watina, "1/1/2010") -#' mydata +#' mydata %>% arrange(loc_code, date, chem_variable) #' mydata %>% #' pull(date) %>% #' lubridate::year(.) %>% diff --git a/R/extract.R b/R/extract.R index 9bfc2ce..22cb792 100644 --- a/R/extract.R +++ b/R/extract.R @@ -69,7 +69,7 @@ #' mydata <- #' mylocs %>% #' get_xg3(watina, 1900) -#' mydata +#' mydata %>% arrange(loc_code, hydroyear) #' mydata %>% #' extract_xg3_series(xg3_type = c("L", "V"), #' max_gap = 2, diff --git a/R/get.R b/R/get.R index 72acba4..4eb6b1c 100644 --- a/R/get.R +++ b/R/get.R @@ -211,7 +211,8 @@ #' bbox = c(xmin = 1.4e+5, #' xmax = 1.7e+5, #' ymin = 1.6e+5, -#' ymax = 1.9e+5)) +#' ymax = 1.9e+5)) %>% +#' arrange(area_code, loc_code) #' #' get_locs(watina, #' area_codes = c("KAL", "KBR"), @@ -759,17 +760,22 @@ get_locs <- function(con, #' watina <- connect_watina() #' library(dplyr) #' mylocs <- get_locs(watina, area_codes = "KAL") -#' mylocs %>% get_xg3(watina, 2010) +#' mylocs %>% +#' get_xg3(watina, 2010) %>% +#' arrange(loc_code, hydroyear) #' mylocs %>% get_xg3(watina, 2010, collect = TRUE) -#' mylocs %>% get_xg3(watina, 2010, vert_crs = "ostend") +#' mylocs %>% +#' get_xg3(watina, 2010, vert_crs = "ostend") %>% +#' arrange(loc_code, hydroyear) #' #' # joining results to mylocs: #' mylocs %>% -#' get_xg3(watina, 2010) %>% -#' left_join(mylocs %>% -#' select(-loc_wid), -#' .) %>% -#' collect +#' get_xg3(watina, 2010) %>% +#' left_join(mylocs %>% +#' select(-loc_wid), +#' .) %>% +#' collect %>% +#' arrange(loc_code, hydroyear) #' #' # Disconnect: #' DBI::dbDisconnect(watina) @@ -1012,9 +1018,14 @@ get_xg3 <- function(locs, #' watina <- connect_watina() #' library(dplyr) #' mylocs <- get_locs(watina, area_codes = "ZWA") -#' mylocs %>% get_chem(watina, "1/1/2017") -#' mylocs %>% get_chem(watina, "1/1/2017", collect = TRUE) -#' mylocs %>% get_chem(watina, "1/1/2017", conc_type = "eq") +#' mylocs %>% +#' get_chem(watina, "1/1/2017") %>% +#' arrange(loc_code, date, chem_variable) +#' mylocs %>% +#' get_chem(watina, "1/1/2017", collect = TRUE) +#' mylocs %>% +#' get_chem(watina, "1/1/2017", conc_type = "eq") %>% +#' arrange(loc_code, date, chem_variable) #' #' # compare the number of returned rows: #' mylocs %>% get_chem(watina, "1/1/2017") %>% count @@ -1034,7 +1045,8 @@ get_xg3 <- function(locs, #' left_join(mylocs %>% #' select(-loc_wid), #' .) %>% -#' collect +#' collect %>% +#' arrange(loc_code, date, chem_variable) #' #' # Disconnect: #' DBI::dbDisconnect(watina) diff --git a/R/selectlocs.R b/R/selectlocs.R index 6d0eefd..5aee57f 100644 --- a/R/selectlocs.R +++ b/R/selectlocs.R @@ -252,7 +252,7 @@ #' mydata <- #' mylocs %>% #' get_xg3(watina, 2000) -#' mydata +#' mydata %>% arrange(loc_code, hydroyear) #' # Number of locations in mydata: #' mydata %>% distinct(loc_code) %>% count #' # Number of hydrological years per location and XG3 variable: @@ -876,7 +876,7 @@ selectlocs_xg3 <- function(data, #' mydata <- #' mylocs %>% #' get_chem(watina, "1/1/2010") -#' mydata +#' mydata %>% arrange(loc_code, date, chem_variable) #' mydata %>% #' pull(date) %>% #' lubridate::year(.) %>% diff --git a/man/eval_chem.Rd b/man/eval_chem.Rd index d13514e..2f1d303 100644 --- a/man/eval_chem.Rd +++ b/man/eval_chem.Rd @@ -117,7 +117,7 @@ mylocs <- get_locs(watina, area_codes = "ZWA") mydata <- mylocs \%>\% get_chem(watina, "1/1/2010") -mydata +mydata \%>\% arrange(loc_code, date, chem_variable) mydata \%>\% pull(date) \%>\% lubridate::year(.) \%>\% diff --git a/man/eval_xg3_avail.Rd b/man/eval_xg3_avail.Rd index 84c1962..9d91549 100644 --- a/man/eval_xg3_avail.Rd +++ b/man/eval_xg3_avail.Rd @@ -45,7 +45,7 @@ mylocs <- get_locs(watina, area_codes = "KAL") mydata <- mylocs \%>\% get_xg3(watina, 2014) -mydata +mydata \%>\% arrange(loc_code, hydroyear) eval_xg3_avail(mydata, xg3_type = c("L", "V")) # Disconnect: diff --git a/man/eval_xg3_series.Rd b/man/eval_xg3_series.Rd index 89f1a44..530cd1a 100644 --- a/man/eval_xg3_series.Rd +++ b/man/eval_xg3_series.Rd @@ -117,7 +117,7 @@ mylocs <- get_locs(watina, area_codes = "KAL") mydata <- mylocs \%>\% get_xg3(watina, 1900) -mydata +mydata \%>\% arrange(loc_code, hydroyear) mydata \%>\% eval_xg3_series(xg3_type = c("L", "V"), max_gap = 2, diff --git a/man/extract_xg3_series.Rd b/man/extract_xg3_series.Rd index dde4b1b..1d80195 100644 --- a/man/extract_xg3_series.Rd +++ b/man/extract_xg3_series.Rd @@ -82,7 +82,7 @@ mylocs <- get_locs(watina, area_codes = "KAL") mydata <- mylocs \%>\% get_xg3(watina, 1900) -mydata +mydata \%>\% arrange(loc_code, hydroyear) mydata \%>\% extract_xg3_series(xg3_type = c("L", "V"), max_gap = 2, diff --git a/man/get_chem.Rd b/man/get_chem.Rd index 5d0eb70..dd1b804 100644 --- a/man/get_chem.Rd +++ b/man/get_chem.Rd @@ -151,9 +151,14 @@ If you like to print the lazy object in a sorted manner, you must add watina <- connect_watina() library(dplyr) mylocs <- get_locs(watina, area_codes = "ZWA") -mylocs \%>\% get_chem(watina, "1/1/2017") -mylocs \%>\% get_chem(watina, "1/1/2017", collect = TRUE) -mylocs \%>\% get_chem(watina, "1/1/2017", conc_type = "eq") +mylocs \%>\% + get_chem(watina, "1/1/2017") \%>\% + arrange(loc_code, date, chem_variable) +mylocs \%>\% + get_chem(watina, "1/1/2017", collect = TRUE) +mylocs \%>\% + get_chem(watina, "1/1/2017", conc_type = "eq") \%>\% + arrange(loc_code, date, chem_variable) # compare the number of returned rows: mylocs \%>\% get_chem(watina, "1/1/2017") \%>\% count @@ -173,7 +178,8 @@ get_chem(watina, "1/1/2017") \%>\% left_join(mylocs \%>\% select(-loc_wid), .) \%>\% - collect + collect \%>\% + arrange(loc_code, date, chem_variable) # Disconnect: DBI::dbDisconnect(watina) diff --git a/man/get_locs.Rd b/man/get_locs.Rd index db0351c..aa73627 100644 --- a/man/get_locs.Rd +++ b/man/get_locs.Rd @@ -242,7 +242,8 @@ get_locs(watina, bbox = c(xmin = 1.4e+5, xmax = 1.7e+5, ymin = 1.6e+5, - ymax = 1.9e+5)) + ymax = 1.9e+5)) \%>\% + arrange(area_code, loc_code) get_locs(watina, area_codes = c("KAL", "KBR"), diff --git a/man/get_xg3.Rd b/man/get_xg3.Rd index f177a3d..8a7bfa5 100644 --- a/man/get_xg3.Rd +++ b/man/get_xg3.Rd @@ -101,17 +101,22 @@ If you like to print the lazy object in a sorted manner, you must add watina <- connect_watina() library(dplyr) mylocs <- get_locs(watina, area_codes = "KAL") -mylocs \%>\% get_xg3(watina, 2010) +mylocs \%>\% + get_xg3(watina, 2010) \%>\% + arrange(loc_code, hydroyear) mylocs \%>\% get_xg3(watina, 2010, collect = TRUE) -mylocs \%>\% get_xg3(watina, 2010, vert_crs = "ostend") +mylocs \%>\% + get_xg3(watina, 2010, vert_crs = "ostend") \%>\% + arrange(loc_code, hydroyear) # joining results to mylocs: mylocs \%>\% - get_xg3(watina, 2010) \%>\% - left_join(mylocs \%>\% - select(-loc_wid), - .) \%>\% - collect + get_xg3(watina, 2010) \%>\% + left_join(mylocs \%>\% + select(-loc_wid), + .) \%>\% + collect \%>\% + arrange(loc_code, hydroyear) # Disconnect: DBI::dbDisconnect(watina) diff --git a/man/selectlocs_chem.Rd b/man/selectlocs_chem.Rd index dea2e9a..a254a32 100644 --- a/man/selectlocs_chem.Rd +++ b/man/selectlocs_chem.Rd @@ -183,7 +183,7 @@ mylocs <- get_locs(watina, area_codes = "ZWA") mydata <- mylocs \%>\% get_chem(watina, "1/1/2010") -mydata +mydata \%>\% arrange(loc_code, date, chem_variable) mydata \%>\% pull(date) \%>\% lubridate::year(.) \%>\% diff --git a/man/selectlocs_xg3.Rd b/man/selectlocs_xg3.Rd index 023c954..ccb1387 100644 --- a/man/selectlocs_xg3.Rd +++ b/man/selectlocs_xg3.Rd @@ -279,7 +279,7 @@ mylocs <- get_locs(watina, mydata <- mylocs \%>\% get_xg3(watina, 2000) -mydata +mydata \%>\% arrange(loc_code, hydroyear) # Number of locations in mydata: mydata \%>\% distinct(loc_code) \%>\% count # Number of hydrological years per location and XG3 variable: From f3bd07aa50427829e117b30af6022cc61d2e0f1b Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 11 Jan 2021 19:48:28 +0100 Subject: [PATCH 12/34] eval_chem(): arrange lazy input data --- R/eval.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/eval.R b/R/eval.R index 6b806fc..9840920 100644 --- a/R/eval.R +++ b/R/eval.R @@ -676,7 +676,11 @@ date, lab_sample_id, chem_variable, value, unit, below_loq." filter(.data$chem_variable %in% chem_var) if (inherits(data, "tbl_lazy")) { - data <- collect(data) + data <- + collect(data) %>% + arrange(.data$loc_code, + .data$date, + .data$chem_variable) } if (!missing(chem_var)) { From 7901459db3b0c9f916e15528521a4bec8b43e411 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Tue, 12 Jan 2021 09:46:20 +0100 Subject: [PATCH 13/34] get_locs() docu: minor update of arrange() note --- R/get.R | 2 +- man/get_locs.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/get.R b/R/get.R index 4eb6b1c..5643a34 100644 --- a/R/get.R +++ b/R/get.R @@ -143,7 +143,7 @@ #' #' @note #' Up to and including `watina 0.3.0`, the result was sorted according to -#' `area_code`, `loc_code` and (for observation wells) `obswell_rank`, +#' `area_code` and `loc_code`, #' both for the lazy query and the collected result. #' Later versions avoid sorting in case of a lazy result, because #' otherwise, when using the result inside another lazy query, this led to diff --git a/man/get_locs.Rd b/man/get_locs.Rd index aa73627..691f55f 100644 --- a/man/get_locs.Rd +++ b/man/get_locs.Rd @@ -224,7 +224,7 @@ measurement device). } \note{ Up to and including \verb{watina 0.3.0}, the result was sorted according to -\code{area_code}, \code{loc_code} and (for observation wells) \code{obswell_rank}, +\code{area_code} and \code{loc_code}, both for the lazy query and the collected result. Later versions avoid sorting in case of a lazy result, because otherwise, when using the result inside another lazy query, this led to From 95783bceeb4ddd8d184ba09b59f0d90d1398a491 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Tue, 12 Jan 2021 11:00:26 +0100 Subject: [PATCH 14/34] connect_watina(): rely on inbodb for UTF-8 encoding * This led to abandoning watina::collect() and watina::convertdf_enc(). See inborutils::convertdf_enc() if you need it. --- NAMESPACE | 4 +- R/connect_watina.R | 3 +- R/encode_utf8.R | 104 ------------------------------------------- R/eval.R | 3 ++ _pkgdown.yml | 2 - man/collect.Rd | 30 ------------- man/convertdf_enc.Rd | 35 --------------- 7 files changed, 6 insertions(+), 175 deletions(-) delete mode 100644 R/encode_utf8.R delete mode 100644 man/collect.Rd delete mode 100644 man/convertdf_enc.Rd diff --git a/NAMESPACE b/NAMESPACE index 3908b35..f769ade 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,9 +2,7 @@ export(as_points) export(cluster_locs) -export(collect) export(connect_watina) -export(convertdf_enc) export(eval_chem) export(eval_xg3_avail) export(eval_xg3_series) @@ -28,6 +26,7 @@ importFrom(dplyr,anti_join) importFrom(dplyr,arrange) importFrom(dplyr,as_tibble) importFrom(dplyr,bind_cols) +importFrom(dplyr,collect) importFrom(dplyr,contains) importFrom(dplyr,copy_to) importFrom(dplyr,count) @@ -42,7 +41,6 @@ importFrom(dplyr,lead) importFrom(dplyr,left_join) importFrom(dplyr,mutate) importFrom(dplyr,mutate_at) -importFrom(dplyr,mutate_if) importFrom(dplyr,n) importFrom(dplyr,pull) importFrom(dplyr,rename) diff --git a/R/connect_watina.R b/R/connect_watina.R index 42c8c10..82991db 100644 --- a/R/connect_watina.R +++ b/R/connect_watina.R @@ -20,6 +20,7 @@ #' @export #' @importFrom inbodb connect_inbo_dbase connect_watina <- function() { - connect_inbo_dbase("W0002_00_Watina") + connect_inbo_dbase("W0002_00_Watina", + autoconvert_utf8 = TRUE) } diff --git a/R/encode_utf8.R b/R/encode_utf8.R deleted file mode 100644 index 4c6f0c4..0000000 --- a/R/encode_utf8.R +++ /dev/null @@ -1,104 +0,0 @@ -#' Convert encoding of character and factor variables in a dataframe -#' -#' @details -#' Encoding strings: all \code{R} platforms support \code{""} (for the -#' encoding of the current -#' locale), \code{"latin1"} and \code{"UTF-8"}. -#' See \code{\link[base]{iconv}} for more information. -#' -#' @param x A dataframe or an object (such as `sf`) with the `data.frame` -#' class -#' -#' @inheritParams base::iconv -#' -#' @md -#' -#' @return -#' The original object, with character variables (and levels of -#' (character) factor variables) converted to the specified encoding. -#' -#' @export -#' @importFrom dplyr -#' %>% -#' mutate_if -#' @importFrom assertthat -#' assert_that -#' is.string -convertdf_enc <- function(x, - from = "", - to = "UTF-8", - sub = NA) { - - assert_that(inherits(x, "data.frame")) - assert_that(is.string(to)) - - is_chfact <- function(vec) { - if (is.factor(vec)) { - is.character(levels(vec)) - } else FALSE - } - - conv_levels <- function(fact, from, to, sub) { - levels(fact) <- iconv(levels(fact), - from = from, - to = to, - sub = sub) - return(fact) - } - - x %>% - mutate_if(is.character, - iconv, - from = from, - to = to, - sub = sub) %>% - mutate_if(is_chfact, - conv_levels, - from = from, - to = to, - sub = sub) - -} - - - - - - - -#' A variant of dplyr's collect() which converts dataframes to UTF-8 encoding -#' if OS is Windows -#' -#' Works as a simple \code{\link[dplyr:compute]{collect()}}, on which it is -#' based. -#' However, on a Windows OS the \code{collect()} function exported -#' by this package will convert character and factor -#' variables of dataframes to \code{UTF-8} encoding. -#' -#' The functions in this package that \emph{collect} a \code{tbl_lazy} object, -#' e.g. when \code{collect = TRUE}, do so by using this function. -#' As a convenience to the user, the function is exported to allow manual -#' implementation. -#' -#' The function \code{\link[=convertdf_enc]{convertdf_enc()}} is the workhorse -#' for the encoding conversion. -#' -#' @inheritParams dplyr::collect -#' -#' @export -#' @importFrom dplyr -#' %>% -collect <- function(x) { - result <- - dplyr::collect(x) - - if (.Platform$OS.type == "windows") { - result <- - result %>% - convertdf_enc(to = "UTF-8") - } - - return(result) -} - - diff --git a/R/eval.R b/R/eval.R index 9840920..7f92a41 100644 --- a/R/eval.R +++ b/R/eval.R @@ -200,6 +200,7 @@ filter_xg3 <- function(data, #' contains #' vars #' mutate_at +#' collect qualify_xg3 <- function(data, xg3_type) { @@ -375,6 +376,7 @@ qualify_xg3 <- function(data, #' n #' first #' ungroup +#' collect eval_xg3_series <- function(data, xg3_type = c("L", "H", "V"), max_gap, @@ -631,6 +633,7 @@ eval_xg3_series <- function(data, #' left_join #' filter #' first +#' collect #' @importFrom tidyr #' spread #' gather diff --git a/_pkgdown.yml b/_pkgdown.yml index d75147c..91cdc72 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -30,5 +30,3 @@ reference: - as_points - cluster_locs - extract_xg3_series - - collect - - convertdf_enc diff --git a/man/collect.Rd b/man/collect.Rd deleted file mode 100644 index 7c69f19..0000000 --- a/man/collect.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/encode_utf8.R -\name{collect} -\alias{collect} -\title{A variant of dplyr's collect() which converts dataframes to UTF-8 encoding -if OS is Windows} -\usage{ -collect(x) -} -\arguments{ -\item{x}{A data frame, data frame extension (e.g. a tibble), or a lazy -data frame (e.g. from dbplyr or dtplyr). See \emph{Methods}, below, for more -details.} -} -\description{ -Works as a simple \code{\link[dplyr:compute]{collect()}}, on which it is -based. -However, on a Windows OS the \code{collect()} function exported -by this package will convert character and factor -variables of dataframes to \code{UTF-8} encoding. -} -\details{ -The functions in this package that \emph{collect} a \code{tbl_lazy} object, -e.g. when \code{collect = TRUE}, do so by using this function. -As a convenience to the user, the function is exported to allow manual -implementation. - -The function \code{\link[=convertdf_enc]{convertdf_enc()}} is the workhorse -for the encoding conversion. -} diff --git a/man/convertdf_enc.Rd b/man/convertdf_enc.Rd deleted file mode 100644 index 345d5ad..0000000 --- a/man/convertdf_enc.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/encode_utf8.R -\name{convertdf_enc} -\alias{convertdf_enc} -\title{Convert encoding of character and factor variables in a dataframe} -\usage{ -convertdf_enc(x, from = "", to = "UTF-8", sub = NA) -} -\arguments{ -\item{x}{A dataframe or an object (such as \code{sf}) with the \code{data.frame} -class} - -\item{from}{A character string describing the current encoding.} - -\item{to}{A character string describing the target encoding.} - -\item{sub}{character string. If not \code{NA} it is used to replace - any non-convertible bytes in the input. (This would normally be a - single character, but can be more.) If \code{"byte"}, the indication is - \code{""} with the hex code of the byte. If \code{"Unicode"} - and converting from UTF-8, the Unicode point in the form \code{""}.} -} -\value{ -The original object, with character variables (and levels of -(character) factor variables) converted to the specified encoding. -} -\description{ -Convert encoding of character and factor variables in a dataframe -} -\details{ -Encoding strings: all \code{R} platforms support \code{""} (for the -encoding of the current -locale), \code{"latin1"} and \code{"UTF-8"}. -See \code{\link[base]{iconv}} for more information. -} From 6e429877a10e7cb20df1b43b19f6dcad99640c76 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Tue, 12 Jan 2021 11:07:03 +0100 Subject: [PATCH 15/34] Add dbDisconnect() as a re-export of inbodb::dbDisconnect() --- NAMESPACE | 2 ++ R/cluster.R | 2 +- R/connect_watina.R | 16 ++++++++++++++-- R/eval.R | 6 +++--- R/extract.R | 2 +- R/get.R | 6 +++--- R/selectlocs.R | 4 ++-- _pkgdown.yml | 1 + man/cluster_locs.Rd | 2 +- man/connect_watina.Rd | 4 ++-- man/dbDisconnect.Rd | 10 ++++++++++ man/eval_chem.Rd | 2 +- man/eval_xg3_avail.Rd | 2 +- man/eval_xg3_series.Rd | 2 +- man/extract_xg3_series.Rd | 2 +- man/get_chem.Rd | 2 +- man/get_locs.Rd | 2 +- man/get_xg3.Rd | 2 +- man/selectlocs_chem.Rd | 2 +- man/selectlocs_xg3.Rd | 2 +- vignettes/v010_getstarted.Rmd | 2 +- vignettes/v110_xg3.Rmd | 2 +- vignettes/v210_chem.Rmd | 2 +- 23 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 man/dbDisconnect.Rd diff --git a/NAMESPACE b/NAMESPACE index f769ade..9a40c7e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(as_points) export(cluster_locs) export(connect_watina) +export(dbDisconnect) export(eval_chem) export(eval_xg3_avail) export(eval_xg3_series) @@ -57,6 +58,7 @@ importFrom(dplyr,tribble) importFrom(dplyr,ungroup) importFrom(dplyr,vars) importFrom(inbodb,connect_inbo_dbase) +importFrom(inbodb,dbDisconnect) importFrom(lubridate,as_date) importFrom(lubridate,day) importFrom(lubridate,dmy) diff --git a/R/cluster.R b/R/cluster.R index 7121a97..d237372 100644 --- a/R/cluster.R +++ b/R/cluster.R @@ -81,7 +81,7 @@ #' table #' #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export diff --git a/R/connect_watina.R b/R/connect_watina.R index 82991db..61978b5 100644 --- a/R/connect_watina.R +++ b/R/connect_watina.R @@ -4,7 +4,7 @@ #' The function can only be used from within the INBO network. #' #' Don't forget to disconnect at the end of your R-script using -#' \code{\link[DBI:dbDisconnect]{DBI::dbDisconnect()}}! +#' \code{\link{dbDisconnect}}! #' #' @return #' A \code{DBIConnection} object. @@ -14,7 +14,7 @@ #' watina <- connect_watina() #' # Do your stuff. #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export @@ -24,3 +24,15 @@ connect_watina <- function() { autoconvert_utf8 = TRUE) } + + +#' Disconnect a database connection +#' +#' This is a re-export of +#' \code{\link[inbodb:dbDisconnect-OdbcConnection-method]{inbodb::dbDisconnect()}}. +#' +#' @name dbDisconnect +#' @keywords documentation +#' @importFrom inbodb dbDisconnect +#' @export dbDisconnect +NULL diff --git a/R/eval.R b/R/eval.R index 7f92a41..87e01e9 100644 --- a/R/eval.R +++ b/R/eval.R @@ -37,7 +37,7 @@ #' eval_xg3_avail(mydata, #' xg3_type = c("L", "V")) #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @@ -347,7 +347,7 @@ qualify_xg3 <- function(data, #' max_gap = 2, #' min_dur = 5) #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export @@ -613,7 +613,7 @@ eval_xg3_series <- function(data, #' arrange(desc(loc_code)) %>% #' select(loc_code, chem_variable, pval_uniform_totalspan) #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' diff --git a/R/extract.R b/R/extract.R index 22cb792..a19806b 100644 --- a/R/extract.R +++ b/R/extract.R @@ -75,7 +75,7 @@ #' max_gap = 2, #' min_dur = 5) #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export diff --git a/R/get.R b/R/get.R index 5643a34..7a36852 100644 --- a/R/get.R +++ b/R/get.R @@ -290,7 +290,7 @@ #' buffer = 0) #' #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export @@ -778,7 +778,7 @@ get_locs <- function(con, #' arrange(loc_code, hydroyear) #' #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export @@ -1049,7 +1049,7 @@ get_xg3 <- function(locs, #' arrange(loc_code, date, chem_variable) #' #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export diff --git a/R/selectlocs.R b/R/selectlocs.R index 5aee57f..51734f1 100644 --- a/R/selectlocs.R +++ b/R/selectlocs.R @@ -290,7 +290,7 @@ #' result$combined_result_filtered #' result[2:4] #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export @@ -925,7 +925,7 @@ selectlocs_xg3 <- function(data, #' conditions = conditions_df) #' #' # Disconnect: -#' DBI::dbDisconnect(watina) +#' dbDisconnect(watina) #' } #' #' @export diff --git a/_pkgdown.yml b/_pkgdown.yml index 91cdc72..ef84d22 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -11,6 +11,7 @@ reference: - title: "Connect" contents: - connect_watina + - dbDisconnect - title: "Get locations" contents: - get_locs diff --git a/man/cluster_locs.Rd b/man/cluster_locs.Rd index d770fba..cef9be7 100644 --- a/man/cluster_locs.Rd +++ b/man/cluster_locs.Rd @@ -100,7 +100,7 @@ clusters \%>\% table # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/connect_watina.Rd b/man/connect_watina.Rd index 9b137e3..4fa34f2 100644 --- a/man/connect_watina.Rd +++ b/man/connect_watina.Rd @@ -15,14 +15,14 @@ The function can only be used from within the INBO network. } \details{ Don't forget to disconnect at the end of your R-script using -\code{\link[DBI:dbDisconnect]{DBI::dbDisconnect()}}! +\code{\link{dbDisconnect}}! } \examples{ \dontrun{ watina <- connect_watina() # Do your stuff. # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/dbDisconnect.Rd b/man/dbDisconnect.Rd new file mode 100644 index 0000000..bd515d9 --- /dev/null +++ b/man/dbDisconnect.Rd @@ -0,0 +1,10 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/connect_watina.R +\name{dbDisconnect} +\alias{dbDisconnect} +\title{Disconnect a database connection} +\description{ +This is a re-export of +\code{\link[inbodb:dbDisconnect-OdbcConnection-method]{inbodb::dbDisconnect()}}. +} +\keyword{documentation} diff --git a/man/eval_chem.Rd b/man/eval_chem.Rd index 2f1d303..747053f 100644 --- a/man/eval_chem.Rd +++ b/man/eval_chem.Rd @@ -137,7 +137,7 @@ mydata \%>\% arrange(desc(loc_code)) \%>\% select(loc_code, chem_variable, pval_uniform_totalspan) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } diff --git a/man/eval_xg3_avail.Rd b/man/eval_xg3_avail.Rd index 9d91549..0f42f71 100644 --- a/man/eval_xg3_avail.Rd +++ b/man/eval_xg3_avail.Rd @@ -49,7 +49,7 @@ mydata \%>\% arrange(loc_code, hydroyear) eval_xg3_avail(mydata, xg3_type = c("L", "V")) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } diff --git a/man/eval_xg3_series.Rd b/man/eval_xg3_series.Rd index 530cd1a..8ed3486 100644 --- a/man/eval_xg3_series.Rd +++ b/man/eval_xg3_series.Rd @@ -123,7 +123,7 @@ mydata \%>\% max_gap = 2, min_dur = 5) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/extract_xg3_series.Rd b/man/extract_xg3_series.Rd index 1d80195..96f18bc 100644 --- a/man/extract_xg3_series.Rd +++ b/man/extract_xg3_series.Rd @@ -88,7 +88,7 @@ mydata \%>\% max_gap = 2, min_dur = 5) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/get_chem.Rd b/man/get_chem.Rd index dd1b804..ba65f12 100644 --- a/man/get_chem.Rd +++ b/man/get_chem.Rd @@ -182,7 +182,7 @@ get_chem(watina, "1/1/2017") \%>\% arrange(loc_code, date, chem_variable) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/get_locs.Rd b/man/get_locs.Rd index 691f55f..2c4105e 100644 --- a/man/get_locs.Rd +++ b/man/get_locs.Rd @@ -321,7 +321,7 @@ get_locs(watina, buffer = 0) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/get_xg3.Rd b/man/get_xg3.Rd index 8a7bfa5..249b698 100644 --- a/man/get_xg3.Rd +++ b/man/get_xg3.Rd @@ -119,7 +119,7 @@ mylocs \%>\% arrange(loc_code, hydroyear) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/selectlocs_chem.Rd b/man/selectlocs_chem.Rd index a254a32..c8e575c 100644 --- a/man/selectlocs_chem.Rd +++ b/man/selectlocs_chem.Rd @@ -232,7 +232,7 @@ mydata \%>\% conditions = conditions_df) # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/man/selectlocs_xg3.Rd b/man/selectlocs_xg3.Rd index ccb1387..c7fe217 100644 --- a/man/selectlocs_xg3.Rd +++ b/man/selectlocs_xg3.Rd @@ -317,7 +317,7 @@ result <- result$combined_result_filtered result[2:4] # Disconnect: -DBI::dbDisconnect(watina) +dbDisconnect(watina) } } diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index c1b640d..5d734d5 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -262,7 +262,7 @@ get_locs(watina, At the end of your work (a script, a bookdown document etc.), close the connection: ```{r} -DBI::dbDisconnect(watina) +dbDisconnect(watina) ``` diff --git a/vignettes/v110_xg3.Rmd b/vignettes/v110_xg3.Rmd index 86429d2..4700e4d 100644 --- a/vignettes/v110_xg3.Rmd +++ b/vignettes/v110_xg3.Rmd @@ -195,6 +195,6 @@ It calls `eval_xg3_avail()` and `eval_xg3_series()` by itself, but alternatively ```{r include=FALSE} -DBI::dbDisconnect(watina) +dbDisconnect(watina) ``` diff --git a/vignettes/v210_chem.Rmd b/vignettes/v210_chem.Rmd index c01411e..b25c55c 100644 --- a/vignettes/v210_chem.Rmd +++ b/vignettes/v210_chem.Rmd @@ -313,6 +313,6 @@ The `selectlocs_chem()` function, of which we saw a demonstration above, calls ` Alternatively the user can provide the result of those functions as input to `selectlocs_chem()`. ```{r include=FALSE} -DBI::dbDisconnect(watina) +dbDisconnect(watina) ``` From 6ca5f1584312b709e6401a0efb911bbcb027871a Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 14 Jan 2021 15:58:32 +0100 Subject: [PATCH 16/34] get_locs() docu: use WFS instead of BelgiumMaps.StatBel (#62) --- R/get.R | 21 ++++++++++++++------- man/get_locs.Rd | 21 ++++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/R/get.R b/R/get.R index 7a36852..6f48d27 100644 --- a/R/get.R +++ b/R/get.R @@ -275,15 +275,22 @@ #' head(12) #' #' # Selecting all piezometers with status VLD of the -#' # province "West-Vlaanderen": -#' data(BE_ADMIN_PROVINCE, -#' package = "BelgiumMaps.StatBel") +#' # province "West-Vlaanderen" (current polygon taken +#' # from the official WFS service): #' library(sf) -#' library(stringr) +#' library(purrr) +#' library(httr) #' mymask <- -#' st_as_sf(BE_ADMIN_PROVINCE) %>% -#' filter(str_detect(TX_PROV_DESCR_NL, "West")) %>% -#' st_transform(crs = 31370) +#' "https://geoservices.informatievlaanderen.be/overdrachtdiensten/VRBG/wfs" %>% +#' parse_url() %>% +#' list_merge(query = list(request = "GetFeature", +#' typeName = "VRBG:Refprv", +#' cql_filter="NAAM='West-Vlaanderen'", +#' srsName = "EPSG:31370", +#' outputFormat = "text/xml; subtype=gml/3.1.1")) %>% +#' build_url() %>% +#' read_sf(crs = 31370) %>% +#' st_cast("GEOMETRYCOLLECTION") #' get_locs(watina, #' loc_validity = "VLD", #' mask = mymask, diff --git a/man/get_locs.Rd b/man/get_locs.Rd index 2c4105e..45cfc1e 100644 --- a/man/get_locs.Rd +++ b/man/get_locs.Rd @@ -306,15 +306,22 @@ get_locs(watina, head(12) # Selecting all piezometers with status VLD of the -# province "West-Vlaanderen": -data(BE_ADMIN_PROVINCE, - package = "BelgiumMaps.StatBel") +# province "West-Vlaanderen" (current polygon taken +# from the official WFS service): library(sf) -library(stringr) +library(purrr) +library(httr) mymask <- - st_as_sf(BE_ADMIN_PROVINCE) \%>\% - filter(str_detect(TX_PROV_DESCR_NL, "West")) \%>\% - st_transform(crs = 31370) + "https://geoservices.informatievlaanderen.be/overdrachtdiensten/VRBG/wfs" \%>\% + parse_url() \%>\% + list_merge(query = list(request = "GetFeature", + typeName = "VRBG:Refprv", + cql_filter="NAAM='West-Vlaanderen'", + srsName = "EPSG:31370", + outputFormat = "text/xml; subtype=gml/3.1.1")) \%>\% + build_url() \%>\% + read_sf(crs = 31370) \%>\% + st_cast("GEOMETRYCOLLECTION") get_locs(watina, loc_validity = "VLD", mask = mymask, From d04edb6aaf7156ba989407a0b7f08eac1757ab13 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 14 Jan 2021 16:10:52 +0100 Subject: [PATCH 17/34] Vign 010: use WFS instead of BelgiumMaps.StatBel (fix #62) --- vignettes/v010_getstarted.Rmd | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index 5d734d5..bed33a7 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -165,18 +165,23 @@ get_locs(watina, - you can use a geospatial filter of class [sf](https://r-spatial.github.io/sf/) to make selections, by using the `mask` argument: ```{r echo=FALSE, include=FALSE} -data(BE_ADMIN_PROVINCE, - package = "BelgiumMaps.StatBel") -westfl <- - st_as_sf(BE_ADMIN_PROVINCE) %>% - filter(str_detect(TX_PROV_DESCR_NL, "West")) %>% - st_transform(crs = 31370) +westfl <- + "https://geoservices.informatievlaanderen.be/overdrachtdiensten/VRBG/wfs" %>% + httr::parse_url() %>% + purrr::list_merge(query = list(request = "GetFeature", + typeName = "VRBG:Refprv", + cql_filter="NAAM='West-Vlaanderen'", + srsName = "EPSG:31370", + outputFormat = "text/xml; subtype=gml/3.1.1")) %>% + httr::build_url() %>% + read_sf(crs = 31370) %>% + st_cast("GEOMETRYCOLLECTION") ``` ```{r} get_locs(watina, - mask = westfl, + mask = westfl, # sf polygon of the 'West-Vlaanderen' province buffer = 0) #> As a mask always invokes a collect(), the argument 'collect = FALSE' will be ignored. #> Warning in get_locs(watina, mask = westfl, buffer = 0): Dropped 40 From a85e79af782a743b08f2b5343fd040c47423a9ff Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 14 Jan 2021 19:49:43 +0100 Subject: [PATCH 18/34] Vign 010: expand on filterdepth conditions & such --- vignettes/v010_getstarted.Rmd | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index bed33a7..abd83f1 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -117,6 +117,34 @@ get_locs(watina, #> 1 223 ``` +- for groundwater piezometers: by setting conditions on filterdepth. +The filterdepth is the depth of the piezometer's filter below soil surface (unit: m), more specifically referring to _halfway_ the length of the filter. +Conditions can be set by the arguments `filterdepth_range` and `filterdepth_na` (see documentation of `get_locs()`). +Moreover, by setting `filterdepth_guess = TRUE` (default `FALSE`) you can replace missing filterdepths by a conservative value, before applying these conditions. +By default, only filterdepths between 0 and 3 meters below soilsurface are returned and locations with missing filterdepth are dropped. + +Indeed, more records are returned when allowing groundwater piezometers with missing filterdepth: + +```{r} +get_locs(watina, + area_codes = c("KAL", "KBR"), + loc_type = c("P", "S"), + filterdepth_na = TRUE) %>% + count +``` + +Of course you can set further conditions for other variables, by building upon the lazy result of `get_locs()`, e.g.: + +```{r} +get_locs(watina, + area_codes = c("KAL", "KBR"), + loc_type = c("P", "S"), + filterdepth_na = TRUE) %>% + filter(obswell_state == "OK - niet bemeten") %>% + count +``` + + - by using a spatial bounding box (rectangular area), using the Belgian Lambert 72 coordinate reference system (EPSG-code [31370](https://epsg.io/31370)): ```{r} From 48f54bad1f9a74a258d3b6e14978a5bdaae664a2 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 14 Jan 2021 19:50:29 +0100 Subject: [PATCH 19/34] Vign 010: expand on obswell data retrieval --- vignettes/v010_getstarted.Rmd | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index abd83f1..fd76648 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -262,13 +262,16 @@ Note that the lazy object contains a `loc_wid` column, which is an internal data It should not be regarded as a stable ID; hence don't store it for later use (note that lazy objects don't store data). Consequently, the `loc_wid` column is omitted when using `collect = TRUE`. -Optionally, you can also retrieve the individual observation wells that are linked to each location (where each observation well is from a different timeframe): +Optionally, you can retrieve the individual **observation wells** that are linked to each location (where each observation well is from a different timeframe). +In this case, more attributes are returned (specific observation well attributes). +The below example also demonstrates the use of `tibble::glimpse()` to preview all columns: ```{r} get_locs(watina, obswells = TRUE, area_codes = c("KAL", "KBR"), - loc_type = c("P", "S")) + loc_type = c("P", "S")) %>% + glimpse() #> # Source: lazy query [?? x 14] #> # Database: Microsoft SQL Server #> # Ordered by: area_code, loc_code, obswell_rank From 9eda87add2ca8cb2c018bcd2e3bf0d12c05fe95b Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 14 Jan 2021 19:50:39 +0100 Subject: [PATCH 20/34] Vign 010: expand on obswell data aggregation --- vignettes/v010_getstarted.Rmd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index fd76648..855f685 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -292,6 +292,9 @@ get_locs(watina, #> # obswell_rank , filterdepth , soilsurf_ost ``` +With `get_locs(obswells = FALSE)`, which is the default, the observation well variables are aggregated for each location using one of four methods. +The method is set with the argument `obswell_aggr`. +The default, `obswell_aggr = "latest"`, returns the attributes of the most recent observation well that fulfills the `filterdepth_range` and `filterdepth_na` criteria. ## Disconnecting From bf22c018493c8665fd627ed8926481bab340a6ba Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 14 Jan 2021 19:51:19 +0100 Subject: [PATCH 21/34] Vign 010: note about warnings in case of spatial mask usage --- vignettes/v010_getstarted.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index 855f685..81f5ffd 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -232,6 +232,7 @@ get_locs(watina, ``` Note that the default value for `buffer` is 10 meters; it is used to enlarge mask (or shrink it, if `buffer` < 0). +Also, note there are a few warnings to inform about dropped locations and duplicated coordinates. Instead of leaving the output as a `tbl_lazy` object, you can also retrieve it as a tibble (i.e. an easier-to-use type of dataframe) by setting `collect = TRUE`. From 756a19c587f06a41c269f63659a2d0673d8b8a6b Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 14 Jan 2021 20:05:26 +0100 Subject: [PATCH 22/34] Vign 010: add output from today --- vignettes/v010_getstarted.Rmd | 212 +++++++++++++++++++--------------- 1 file changed, 122 insertions(+), 90 deletions(-) diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index 81f5ffd..3d16345 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -20,7 +20,7 @@ library(stringr) library(knitr) ``` -_General note: the below vignette contains frozen output of 17 Sep 2019._ +_General note: the below vignette contains frozen output of 14 Jan 2021._ _This makes it possible to build the package with vignettes without access to the Watina database._ ## Connecting @@ -49,17 +49,29 @@ get_locs(watina) %>% collect %>% as.data.frame #> loc_wid loc_code area_code area_name x y loc_validitycode -#> 1 676 AABP011 AAB Aabeek 178331 209751 VLD -#> 2 677 AABP013 AAB Aabeek 178315 209637 VLD -#> 3 678 AABP014 AAB Aabeek 178310 209590 VLD -#> 4 681 AABP017 AAB Aabeek 178370 209461 VLD -#> 5 682 AABP018 AAB Aabeek 178379 209418 VLD -#> loc_validity loc_typecode loc_typename filterdepth soilsurf_ost -#> 1 Gevalideerd P Peilbuis/Piëzometer 2.90 10.34 -#> 2 Gevalideerd P Peilbuis/Piëzometer 2.71 10.34 -#> 3 Gevalideerd P Peilbuis/Piëzometer 2.74 9.41 -#> 4 Gevalideerd P Peilbuis/Piëzometer 2.72 9.31 -#> 5 Gevalideerd P Peilbuis/Piëzometer 2.58 9.50 +#> 1 45 AABP001 AAB Aabeek 177604 209714 VLD +#> 2 6291 AABP002 AAB Aabeek 177903 209459 VLD +#> 3 28 AABP003 AAB Aabeek 178353 209155 VLD +#> 4 29 AABP004 AAB Aabeek 179544 210259 VLD +#> 5 30 AABP005 AAB Aabeek 179610 210173 VLD +#> loc_validity loc_typecode loc_typename obswell_statecode +#> 1 Gevalideerd P Peilbuis/Piëzometer CONFN +#> 2 Gevalideerd P Peilbuis/Piëzometer CONFN +#> 3 Gevalideerd P Peilbuis/Piëzometer CONFN +#> 4 Gevalideerd P Peilbuis/Piëzometer CONFN +#> 5 Gevalideerd P Peilbuis/Piëzometer CONFN +#> obswell_state soilsurf_ost measuringref_ost tubelength filterlength +#> 1 OK - niet bemeten 10.136 10.656 4 2 +#> 2 OK - niet bemeten 9.590 10.120 4 2 +#> 3 OK - niet bemeten 9.660 10.150 4 2 +#> 4 OK - niet bemeten 10.310 10.730 4 2 +#> 5 OK - niet bemeten 10.480 10.950 4 2 +#> filterdepth +#> 1 2.48 +#> 2 2.47 +#> 3 2.51 +#> 4 2.58 +#> 5 2.53 ``` Selections can be done in a variety of ways -- and these ways can be combined: @@ -69,24 +81,24 @@ Selections can be done in a variety of ways -- and these ways can be combined: ```{r} get_locs(watina, area_codes = c("KAL", "KBR")) -#> # Source: lazy query [?? x 12] -#> # Database: Microsoft SQL Server -#> # Ordered by: area_code, loc_code, obswell_rank, area_code, loc_code +#> # Source: lazy query [?? x 17] +#> # Database: Microsoft SQL Server #> loc_wid loc_code area_code area_name x y loc_validitycode #> -#> 1 2824 KALP022 KAL Kalmthou… 155350 230813 VLD +#> 1 2824 KALP022 KAL Kalmthou… 155356 230811 VLD #> 2 1546 KALP030 KAL Kalmthou… 152990 238600 VLD -#> 3 10069 KALP034 KAL Kalmthou… 152962 231345 VLD -#> 4 1549 KALP035 KAL Kalmthou… 153000 236850 VLD -#> 5 1552 KALP039 KAL Kalmthou… 160940 235060 VLD -#> 6 4327 KALP050 KAL Kalmthou… 153881 233802 VLD -#> 7 6210 KALP051 KAL Kalmthou… 153822 233761 VLD -#> 8 1562 KALP052 KAL Kalmthou… 153822 233761 VLD -#> 9 1563 KALP053 KAL Kalmthou… 153781 233736 VLD -#> 10 6180 KALP054 KAL Kalmthou… 154689 232426 VLD -#> # … with more rows, and 5 more variables: loc_validity , -#> # loc_typecode , loc_typename , filterdepth , -#> # soilsurf_ost +#> 3 6205 KALP032 KAL Kalmthou… 159110 239010 VLD +#> 4 10069 KALP034 KAL Kalmthou… 152962 231345 VLD +#> 5 1549 KALP035 KAL Kalmthou… 153000 236850 VLD +#> 6 1552 KALP039 KAL Kalmthou… 160940 235060 VLD +#> 7 4327 KALP050 KAL Kalmthou… 153881 233802 VLD +#> 8 6210 KALP051 KAL Kalmthou… 153822 233761 VLD +#> 9 1562 KALP052 KAL Kalmthou… 153822 233761 VLD +#> 10 1563 KALP053 KAL Kalmthou… 153781 233736 VLD +#> # … with more rows, and 10 more variables: loc_validity , +#> # loc_typecode , loc_typename , obswell_statecode , +#> # obswell_state , soilsurf_ost , measuringref_ost , +#> # tubelength , filterlength , filterdepth ``` The number of involved locations is given by: @@ -99,7 +111,7 @@ get_locs(watina, #> # Database: Microsoft SQL Server #> n #> -#> 1 188 +#> 1 207 ``` @@ -114,7 +126,7 @@ get_locs(watina, #> # Database: Microsoft SQL Server #> n #> -#> 1 223 +#> 1 247 ``` - for groundwater piezometers: by setting conditions on filterdepth. @@ -131,6 +143,11 @@ get_locs(watina, loc_type = c("P", "S"), filterdepth_na = TRUE) %>% count +#> # Source: lazy query [?? x 1] +#> # Database: Microsoft SQL Server +#> n +#> +#> 1 289 ``` Of course you can set further conditions for other variables, by building upon the lazy result of `get_locs()`, e.g.: @@ -142,6 +159,11 @@ get_locs(watina, filterdepth_na = TRUE) %>% filter(obswell_state == "OK - niet bemeten") %>% count +#> # Source: lazy query [?? x 1] +#> # Database: Microsoft SQL Server +#> n +#> +#> 1 157 ``` @@ -153,24 +175,24 @@ get_locs(watina, xmax = 1.7e+5, ymin = 1.6e+5, ymax = 1.9e+5)) -#> # Source: lazy query [?? x 12] -#> # Database: Microsoft SQL Server -#> # Ordered by: area_code, loc_code, obswell_rank, area_code, loc_code +#> # Source: lazy query [?? x 17] +#> # Database: Microsoft SQL Server #> loc_wid loc_code area_code area_name x y loc_validitycode #> #> 1 10261 ATGP002 ATG Antitank… 169572 186043 VLD -#> 2 5629 DORP016 DOR Dorent 158521 186074 VLD -#> 3 5630 DORP017 DOR Dorent 158442 185925 VLD -#> 4 5632 DORP019 DOR Dorent 158304 184915 VLD -#> 5 5634 DORP020 DOR Dorent 158352 184259 VLD -#> 6 5635 DORP021 DOR Dorent 158103 183853 VLD -#> 7 5586 DORP022 DOR Dorent 157715 184013 VLD -#> 8 5587 DORP023 DOR Dorent 154284 182533 VLD -#> 9 6420 DORP024 DOR Dorent 154823 182431 VLD -#> 10 5580 DORP027 DOR Dorent 155151 182190 VLD -#> # … with more rows, and 5 more variables: loc_validity , -#> # loc_typecode , loc_typename , filterdepth , -#> # soilsurf_ost +#> 2 777 BABP012 BAB Barebeek 160190 180988 VLD +#> 3 5629 DORP016 DOR Dorent 158521 186074 VLD +#> 4 5630 DORP017 DOR Dorent 158442 185925 VLD +#> 5 5632 DORP019 DOR Dorent 158304 184915 VLD +#> 6 5634 DORP020 DOR Dorent 158352 184259 VLD +#> 7 5635 DORP021 DOR Dorent 158103 183853 VLD +#> 8 5586 DORP022 DOR Dorent 157715 184013 VLD +#> 9 5587 DORP023 DOR Dorent 154284 182533 VLD +#> 10 6420 DORP024 DOR Dorent 154823 182431 VLD +#> # … with more rows, and 10 more variables: loc_validity , +#> # loc_typecode , loc_typename , obswell_statecode , +#> # obswell_state , soilsurf_ost , measuringref_ost , +#> # tubelength , filterlength , filterdepth ``` - if you already have specific location codes in mind, you can provide these directly as a vector: @@ -178,16 +200,17 @@ get_locs(watina, ```{r} get_locs(watina, loc_vec = c("KBRP081", "KBRP090", "KBRP095")) -#> # Source: lazy query [?? x 12] -#> # Database: Microsoft SQL Server -#> # Ordered by: area_code, loc_code, obswell_rank, area_code, loc_code +#> # Source: lazy query [?? x 17] +#> # Database: Microsoft SQL Server #> loc_wid loc_code area_code area_name x y loc_validitycode #> -#> 1 664 KBRP081 KBR Potpolde… 145846 204871 VLD -#> 2 698 KBRP090 KBR Potpolde… 145988 204702 VLD -#> 3 709 KBRP095 KBR Potpolde… 145949 204712 VLD -#> # … with 5 more variables: loc_validity , loc_typecode , -#> # loc_typename , filterdepth , soilsurf_ost +#> 1 664 KBRP081 KBR Polders … 145846 204871 VLD +#> 2 698 KBRP090 KBR Polders … 145988 204702 VLD +#> 3 709 KBRP095 KBR Polders … 145949 204712 VLD +#> # … with 10 more variables: loc_validity , loc_typecode , +#> # loc_typename , obswell_statecode , obswell_state , +#> # soilsurf_ost , measuringref_ost , tubelength , +#> # filterlength , filterdepth ``` - you can use a geospatial filter of class [sf](https://r-spatial.github.io/sf/) to make selections, by using the `mask` argument: @@ -212,9 +235,9 @@ get_locs(watina, mask = westfl, # sf polygon of the 'West-Vlaanderen' province buffer = 0) #> As a mask always invokes a collect(), the argument 'collect = FALSE' will be ignored. -#> Warning in get_locs(watina, mask = westfl, buffer = 0): Dropped 40 -#> locations from which x or y coordinates were missing. -#> # A tibble: 781 x 11 +#> Warning in get_locs(watina, mask = westfl, buffer = 0): Dropped 44 locations from which x or y coordinates were missing. +#> Warning in warn_xy_duplicates(locs$x, locs$y): 28 different coordinate pairs occur more than once. +#> # A tibble: 905 x 16 #> loc_code area_code area_name x y loc_validitycode loc_validity #> * #> 1 ASSP001 ASS Assebroe… 74324 208838 VLD Gevalideerd @@ -227,8 +250,10 @@ get_locs(watina, #> 8 ASSP008 ASS Assebroe… 73948 209104 VLD Gevalideerd #> 9 ASSP009 ASS Assebroe… 73613 208584 VLD Gevalideerd #> 10 ASSP010 ASS Assebroe… 73583 208390 VLD Gevalideerd -#> # … with 771 more rows, and 4 more variables: loc_typecode , -#> # loc_typename , filterdepth , soilsurf_ost +#> # … with 895 more rows, and 9 more variables: loc_typecode , +#> # loc_typename , obswell_statecode , obswell_state , +#> # soilsurf_ost , measuringref_ost , tubelength , +#> # filterlength , filterdepth ``` Note that the default value for `buffer` is 10 meters; it is used to enlarge mask (or shrink it, if `buffer` < 0). @@ -240,23 +265,25 @@ Instead of leaving the output as a `tbl_lazy` object, you can also retrieve it a get_locs(watina, area_codes = c("KAL", "KBR"), loc_type = c("P", "S"), - collect = TRUE - ) -#> # A tibble: 223 x 11 + collect = TRUE) +#> Warning in warn_xy_duplicates(locs$x, locs$y): 15 different coordinate pairs occur more than once. +#> # A tibble: 247 x 16 #> loc_code area_code area_name x y loc_validitycode loc_validity #> -#> 1 KBRP081 KBR Potpolde… 145846 204871 VLD Gevalideerd -#> 2 KBRP090 KBR Potpolde… 145988 204702 VLD Gevalideerd -#> 3 KBRP095 KBR Potpolde… 145949 204712 VLD Gevalideerd -#> 4 KBRS001 KBR Potpolde… 146937 205586 VLD Gevalideerd -#> 5 KALP030 KAL Kalmthou… 152990 238600 VLD Gevalideerd -#> 6 KALP035 KAL Kalmthou… 153000 236850 VLD Gevalideerd -#> 7 KALP039 KAL Kalmthou… 160940 235060 VLD Gevalideerd -#> 8 KALP052 KAL Kalmthou… 153822 233761 VLD Gevalideerd -#> 9 KALP053 KAL Kalmthou… 153781 233736 VLD Gevalideerd -#> 10 KALP059 KAL Kalmthou… 154754 232459 VLD Gevalideerd -#> # … with 213 more rows, and 4 more variables: loc_typecode , -#> # loc_typename , filterdepth , soilsurf_ost +#> 1 KALP022 KAL Kalmthou… 155356 230811 VLD Gevalideerd +#> 2 KALP030 KAL Kalmthou… 152990 238600 VLD Gevalideerd +#> 3 KALP032 KAL Kalmthou… 159110 239010 VLD Gevalideerd +#> 4 KALP034 KAL Kalmthou… 152962 231345 VLD Gevalideerd +#> 5 KALP035 KAL Kalmthou… 153000 236850 VLD Gevalideerd +#> 6 KALP039 KAL Kalmthou… 160940 235060 VLD Gevalideerd +#> 7 KALP050 KAL Kalmthou… 153881 233802 VLD Gevalideerd +#> 8 KALP051 KAL Kalmthou… 153822 233761 VLD Gevalideerd +#> 9 KALP052 KAL Kalmthou… 153822 233761 VLD Gevalideerd +#> 10 KALP053 KAL Kalmthou… 153781 233736 VLD Gevalideerd +#> # … with 237 more rows, and 9 more variables: loc_typecode , +#> # loc_typename , obswell_statecode , obswell_state , +#> # soilsurf_ost , measuringref_ost , tubelength , +#> # filterlength , filterdepth ``` Note that the lazy object contains a `loc_wid` column, which is an internal database variable to identify locations and make relations between tables. @@ -273,24 +300,29 @@ get_locs(watina, area_codes = c("KAL", "KBR"), loc_type = c("P", "S")) %>% glimpse() -#> # Source: lazy query [?? x 14] -#> # Database: Microsoft SQL Server -#> # Ordered by: area_code, loc_code, obswell_rank -#> loc_wid loc_code area_code area_name x y loc_validitycode -#> -#> 1 2824 KALP022 KAL Kalmthou… 155350 230813 VLD -#> 2 1546 KALP030 KAL Kalmthou… 152990 238600 VLD -#> 3 10069 KALP034 KAL Kalmthou… 152962 231345 VLD -#> 4 1549 KALP035 KAL Kalmthou… 153000 236850 VLD -#> 5 1552 KALP039 KAL Kalmthou… 160940 235060 VLD -#> 6 4327 KALP050 KAL Kalmthou… 153881 233802 VLD -#> 7 6210 KALP051 KAL Kalmthou… 153822 233761 VLD -#> 8 1562 KALP052 KAL Kalmthou… 153822 233761 VLD -#> 9 1563 KALP053 KAL Kalmthou… 153781 233736 VLD -#> 10 6180 KALP054 KAL Kalmthou… 154689 232426 VLD -#> # … with more rows, and 7 more variables: loc_validity , -#> # loc_typecode , loc_typename , obswell_code , -#> # obswell_rank , filterdepth , soilsurf_ost +#> Rows: ?? +#> Columns: 21 +#> $ loc_wid 1546, 1549, 1552, 1562, 1563, 1564, 1565, 1566, 1… +#> $ loc_code "KALP030", "KALP035", "KALP039", "KALP052", "KALP… +#> $ area_code "KAL", "KAL", "KAL", "KAL", "KAL", "KAL", "KAL", … +#> $ area_name "Kalmthoutse heide", "Kalmthoutse heide", "Kalmth… +#> $ x 152990, 153000, 160940, 153822, 153781, 154754, 1… +#> $ y 238600, 236850, 235060, 233761, 233736, 232459, 2… +#> $ loc_validitycode "VLD", "VLD", "VLD", "VLD", "VLD", "VLD", "VLD", … +#> $ loc_validity "Gevalideerd", "Gevalideerd", "Gevalideerd", "Gev… +#> $ loc_typecode "P", "P", "P", "P", "P", "P", "P", "P", "P", "P",… +#> $ loc_typename "Peilbuis/Piëzometer", "Peilbuis/Piëzometer", "Pe… +#> $ obswell_code "KALP030X", "KALP035X", "KALP039X", "KALP052X", "… +#> $ obswell_rank 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1… +#> $ obswell_statecode "CONFN", "CONFN", "CONFN", "CONFN", "CONFN", "CON… +#> $ obswell_state "OK - niet bemeten", "OK - niet bemeten", "OK - n… +#> $ obswell_installdate 1982-03-06, 1982-06-28, 1982-03-06, 1999-11-03, … +#> $ obswell_stopdate NA, NA, NA, NA, NA, NA, NA, NA, NA, 2020-05-10, … +#> $ soilsurf_ost 13.420, 15.200, 17.270, 21.060, 21.050, 20.540, 2… +#> $ measuringref_ost 13.580, 15.000, 17.150, 21.580, 21.490, 20.860, 2… +#> $ tubelength 3.12, 0.50, 2.26, 2.02, 2.04, 1.82, 3.25, 2.82, 2… +#> $ filterlength 1.00, 0.50, 1.00, 0.20, 0.30, 0.20, 0.20, 0.20, 0… +#> $ filterdepth 2.460, 0.450, 1.880, 1.400, 1.450, 1.400, 2.700, … ``` With `get_locs(obswells = FALSE)`, which is the default, the observation well variables are aggregated for each location using one of four methods. From f5bb4121c8d0f57dac36015646bbc6a914fc9401 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 09:28:21 +0100 Subject: [PATCH 23/34] dbDisconnect() docu: hardcode inbodb URL * For some reason, pkgdown did not automatically link this one, so making a workaround. May have to do with fact that the Rd name is different from the function name. --- R/connect_watina.R | 3 ++- man/dbDisconnect.Rd | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/connect_watina.R b/R/connect_watina.R index 61978b5..2ff27ec 100644 --- a/R/connect_watina.R +++ b/R/connect_watina.R @@ -29,7 +29,8 @@ connect_watina <- function() { #' Disconnect a database connection #' #' This is a re-export of -#' \code{\link[inbodb:dbDisconnect-OdbcConnection-method]{inbodb::dbDisconnect()}}. +#' \code{\link[inbodb:dbDisconnect-OdbcConnection-method]{inbodb::dbDisconnect()}} +#' (\href{https://inbo.github.io/inbodb/reference/dbDisconnect-OdbcConnection-method.html}{url}). #' #' @name dbDisconnect #' @keywords documentation diff --git a/man/dbDisconnect.Rd b/man/dbDisconnect.Rd index bd515d9..b3cad7b 100644 --- a/man/dbDisconnect.Rd +++ b/man/dbDisconnect.Rd @@ -5,6 +5,7 @@ \title{Disconnect a database connection} \description{ This is a re-export of -\code{\link[inbodb:dbDisconnect-OdbcConnection-method]{inbodb::dbDisconnect()}}. +\code{\link[inbodb:dbDisconnect-OdbcConnection-method]{inbodb::dbDisconnect()}} +(\href{https://inbo.github.io/inbodb/reference/dbDisconnect-OdbcConnection-method.html}{url}). } \keyword{documentation} From f03f51be50a0eccf3d3ec6c7fa1ef9b912ea6dbf Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 09:36:21 +0100 Subject: [PATCH 24/34] Vign 010: minor update filterdepth explanation --- vignettes/v010_getstarted.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/v010_getstarted.Rmd b/vignettes/v010_getstarted.Rmd index 3d16345..de3d402 100644 --- a/vignettes/v010_getstarted.Rmd +++ b/vignettes/v010_getstarted.Rmd @@ -130,7 +130,7 @@ get_locs(watina, ``` - for groundwater piezometers: by setting conditions on filterdepth. -The filterdepth is the depth of the piezometer's filter below soil surface (unit: m), more specifically referring to _halfway_ the length of the filter. +The filterdepth is the depth of the piezometer's filter below soil surface (unit: m), more specifically referring to the position _halfway_ the length of the filter. Conditions can be set by the arguments `filterdepth_range` and `filterdepth_na` (see documentation of `get_locs()`). Moreover, by setting `filterdepth_guess = TRUE` (default `FALSE`) you can replace missing filterdepths by a conservative value, before applying these conditions. By default, only filterdepths between 0 and 3 meters below soilsurface are returned and locations with missing filterdepth are dropped. From 0684b30cfc11e42c0b2024d1e8c5f4b8cf6ac2e0 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 09:48:19 +0100 Subject: [PATCH 25/34] Vign 110: minor update --- vignettes/v110_xg3.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/v110_xg3.Rmd b/vignettes/v110_xg3.Rmd index 4700e4d..ac144af 100644 --- a/vignettes/v110_xg3.Rmd +++ b/vignettes/v110_xg3.Rmd @@ -25,7 +25,7 @@ _This makes it possible to build the package with vignettes without access to th ## Overview -XG3 is an umbrella for the three geohydrological variables LG3, HG3 and VG3, which are yearly statistics which can be calculated from series of water level measurements (on condition that data are frequent enough). +XG3 is an umbrella for the three geohydrological variables LG3, HG3 and VG3, which are yearly statistics which can be calculated from series of water level measurements (on condition that enough data are available). More explanation on these variables is given by the documentation of `get_xg3()`. Let's suppose that we want to select locations (within an area, i.e. after having used `get_locs()`) for which: From eaadadcbae21910fb6f97fc2a44506c3a5bd49d4 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 10:19:17 +0100 Subject: [PATCH 26/34] pkgdown site: switch theme + clearer fonts --- _pkgdown.yml | 2 +- pkgdown/extra.css | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 pkgdown/extra.css diff --git a/_pkgdown.yml b/_pkgdown.yml index ef84d22..954765f 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,6 +1,6 @@ template: params: - bootswatch: yeti + bootswatch: cosmo url: https://inbo.github.io/watina diff --git a/pkgdown/extra.css b/pkgdown/extra.css new file mode 100644 index 0000000..3896cf1 --- /dev/null +++ b/pkgdown/extra.css @@ -0,0 +1,10 @@ +body { + font-size: 18px; +} +pre { + font-size: 16px; +} +pre, code { + background-color: #fdfdfd; + color: #222; +} From c0a59ce0548c519ca70ffc51505a42f4628af1af Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 10:45:51 +0100 Subject: [PATCH 27/34] Changelog: add dates --- NEWS.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1ff4ab5..74c2d31 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# watina 0.3.0 +# watina 0.3.0 (2020-05-20) #### New features @@ -14,34 +14,34 @@ Further, a number of smaller fixes and enhancements were made. -# watina 0.2.6 +# watina 0.2.6 (2020-02-28) - Redo fix `get_locs()`: calculation of `soilsurf_ost` (#43) -# watina 0.2.5 +# watina 0.2.5 (2020-02-27) - Bugfix in `get_locs()`: calculation of `soilsurf_ost` (#42) -# watina 0.2.4 +# watina 0.2.4 (2020-01-29) - Bugfix in `convertdf_enc()` (#34) - Some small documentation improvements -# watina 0.2.3 +# watina 0.2.3 (2020-01-09) - Documentation is now generated by the newer `roxygen2` version `7.0.2`, resulting in a better layout of function arguments in the 'usage' section. -# watina 0.2.2 +# watina 0.2.2 (2019-11-04) - On Windows, the functions now convert 'weird' characters from the database to proper UTF-8. - Bugfix (#29) in `get_locs()` regarding the default implementation of the `loc_validity` argument. -# watina 0.2.1 +# watina 0.2.1 (2019-10-14) - Fixed bug in some hyperlinks in function documentation, affecting the installation process on Windows (warnings were thrown). -# watina 0.2.0 +# watina 0.2.0 (2019-10-02) #### New features From 3986b4e74fcfc5e8a1b93e8d19201795f1ebe941 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 11:22:50 +0100 Subject: [PATCH 28/34] pkgdown site: tweak colour of code anchor --- pkgdown/extra.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgdown/extra.css b/pkgdown/extra.css index 3896cf1..fd261fe 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -8,3 +8,6 @@ pre, code { background-color: #fdfdfd; color: #222; } +code a, pre a { + color: #024b8e; +} From ecad70dc908464398f4d5a64bb458182474b3376 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 11:37:09 +0100 Subject: [PATCH 29/34] Changelog: 0.4.0 --- NEWS.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/NEWS.md b/NEWS.md index 74c2d31..e6adff5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,18 @@ +# watina 0.4.0 (2021-01-18) + +- This release has been made compatible with `dbplyr` 2.0.0 (on CRAN); the `dbplyr` fork is not needed anymore ([e66e58f](https://github.com/inbo/watina/commit/e66e58f), #74). + - Follow the installation procedure on the homepage (readme) to upgrade. + - Lazy results of `get_locs()`, `get_xg3()` or `get_chem()` are not sorted anymore. + Sorting is done in tibbles only, i.e. if `collect = TRUE`. + For more information, consult the _Note_ added in the documentation of these functions. +- Fix broken `selectlocs_xg3()` and `selectlocs_chem()` (#73). +- Fix `get_locs()` error when no results came out of spatial masking ([c96421e](https://github.com/inbo/watina/commit/c96421e)). +- Adopt further [`inbodb`](https://inbo.github.io/inbodb) functionality (#75): + - re-export its `dbDisconnect()`; + - transfer handling of character encoding to `inbodb`. +- Improve documentation and `pkgdown` website (#76, #77, [3986b4e](https://github.com/inbo/watina/commit/3986b4e)). + + # watina 0.3.0 (2020-05-20) #### New features From fbd800bfe26d72fc34cb421529cc153e0bae86e1 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 13:26:02 +0100 Subject: [PATCH 30/34] Changelog: minor updates --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index e6adff5..492c7ba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,11 +2,11 @@ - This release has been made compatible with `dbplyr` 2.0.0 (on CRAN); the `dbplyr` fork is not needed anymore ([e66e58f](https://github.com/inbo/watina/commit/e66e58f), #74). - Follow the installation procedure on the homepage (readme) to upgrade. - - Lazy results of `get_locs()`, `get_xg3()` or `get_chem()` are not sorted anymore. + - Lazy results of `get_locs()`, `get_xg3()` and `get_chem()` are not sorted anymore. Sorting is done in tibbles only, i.e. if `collect = TRUE`. For more information, consult the _Note_ added in the documentation of these functions. - Fix broken `selectlocs_xg3()` and `selectlocs_chem()` (#73). -- Fix `get_locs()` error when no results came out of spatial masking ([c96421e](https://github.com/inbo/watina/commit/c96421e)). +- Fix `get_locs()` error when no locations remain after spatial masking ([c96421e](https://github.com/inbo/watina/commit/c96421e)). - Adopt further [`inbodb`](https://inbo.github.io/inbodb) functionality (#75): - re-export its `dbDisconnect()`; - transfer handling of character encoding to `inbodb`. From 46f9e3c3a449af8a69fa54bf7c00127a59c35d47 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 13:26:36 +0100 Subject: [PATCH 31/34] Buildignore pkgdown folder --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index b614d7e..03e6439 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,6 +6,7 @@ .github/ ^docs$ ^_pkgdown\.yml$ +^pkgdown$ ^\.travis\.yml$ ^appveyor\.yml$ ^\.zenodo\.json$ From ded217d9de6fb2dc752ed596c58b78f5107e129a Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 14:11:54 +0100 Subject: [PATCH 32/34] get_locs(): fix #79 (make obswell_aggr='mean' work) --- R/get.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/get.R b/R/get.R index 6f48d27..e18f3ca 100644 --- a/R/get.R +++ b/R/get.R @@ -597,8 +597,9 @@ get_locs <- function(con, sql("CAST( filterdepth_guessed AS bit)")) } else .} %>% - filter(row_number() == 1L) %>% - ungroup() + ungroup() %>% + filter(.data$obswell_count == 1 | + .data$obswell_rank == .data$obswell_maxrank) ) %>% select(-.data$obswell_code, From 39e69fe03a71275d5990ecdc118e2b30a54eca25 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 14:27:13 +0100 Subject: [PATCH 33/34] Changelog: add #80 --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 492c7ba..4d46f7c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ For more information, consult the _Note_ added in the documentation of these functions. - Fix broken `selectlocs_xg3()` and `selectlocs_chem()` (#73). - Fix `get_locs()` error when no locations remain after spatial masking ([c96421e](https://github.com/inbo/watina/commit/c96421e)). +- Fix `get_locs()` error when `obswell_aggr = "mean"` (#80). - Adopt further [`inbodb`](https://inbo.github.io/inbodb) functionality (#75): - re-export its `dbDisconnect()`; - transfer handling of character encoding to `inbodb`. From 2ed7cd9c660599a6e5cdd8ece355079f4f2c0357 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 18 Jan 2021 14:27:31 +0100 Subject: [PATCH 34/34] Bump version number: 0.4.0 --- .zenodo.json | 2 +- DESCRIPTION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.zenodo.json b/.zenodo.json index 24ea8a4..70fa8db 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -4,7 +4,7 @@ "license": "GPL-3.0", "upload_type": "software", "access_right": "open", - "version": "0.3.0", + "version": "0.4.0", "creators": [ { "name": "Vanderhaeghe, Floris", diff --git a/DESCRIPTION b/DESCRIPTION index 668826a..3ce55ae 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: watina Title: Querying And Processing Data From The INBO Watina Database -Version: 0.3.0.9000 +Version: 0.4.0 Description: The R-package watina contains functions to query and process data from the Watina database at the Research Institute for Nature and Forest (INBO). This database primarily provides