From 79201e1cceced776698ffefe6b8e7b9d22852f07 Mon Sep 17 00:00:00 2001 From: Cidree Date: Fri, 11 Oct 2024 15:10:15 +0200 Subject: [PATCH] restore RODBC --- DESCRIPTION | 3 +-- NEWS.md | 2 -- R/forest-inventory.R | 28 +++++++++++++--------------- cran-comments.md | 4 ++-- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f37d849..b4564f6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,9 +41,8 @@ Collate: 'pathogens.R' Suggests: aws.s3, - DBI, giscoR, - odbc, + RODBC, testthat (>= 3.0.0) Config/testthat/edition: 3 URL: https://cidree.github.io/forestdata/ diff --git a/NEWS.md b/NEWS.md index 8c49da7..983cd9f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,8 +34,6 @@ - Improve documentation, fix mistakes in urls to other functions, add unit tests for all functions, correct wrong `fd_forest_extent_glad()` reference. -- Remove dependency on `RODBC`, and use `DBI` and `odbc` instead in `fd_inventory_spain()`. Improve error message when data is not available. - - `fd_canopy_height()`: now crops and then merges multiples tiles, so it's much faster when using `crop = TRUE`. It acquires argument `mask`, and losses `...` passed to `terra::crop()` because it fails to mask when used within `crop()`. - Now every function have the argument `quiet = FALSE` by default, and retrieves the citation of the dataset. diff --git a/R/forest-inventory.R b/R/forest-inventory.R index c2892f8..a39ed9d 100644 --- a/R/forest-inventory.R +++ b/R/forest-inventory.R @@ -242,8 +242,7 @@ fd_inventory_spain <- function(province, path_metadata = NULL, quiet = FALSE) { # 0. Handle errors - if (!requireNamespace("DBI", quietly = TRUE)) stop("Package `DBI` is required to access the inventory data. Please, install it.") - if (!requireNamespace("odbc", quietly = TRUE)) stop("Package `odbc` is required to access the inventory data. Please, install it.") + if (!requireNamespace("RODBC", quietly = TRUE)) stop("Package `RODBC` is required to access the inventory data. Please, install it.") # 1. Filter province ## 1.1. Fix province province_fix <- province |> @@ -319,24 +318,23 @@ fd_inventory_spain <- function(province, ## 4.1. File name filename <- list.files(dir_unzip, full.names = TRUE, pattern = "\\.accdb$") ## 4.2. Connect to DB - conn <- odbc::dbConnect(odbc::odbc(), - .connection_string = paste0( - "Driver={Microsoft Access Driver (*.mdb, *.accdb)};", - "Dbq=", filename, ";" - )) - ## 4.3. Disconnect on exit - on.exit(DBI::dbDisconnect(conn)) - ## 4.4. Table names - tables_vec <- DBI::dbListTables(conn)[!grepl("^MSys", DBI::dbListTables(conn))] - ## 4.5. Read data into a list + ## 4.2. Connect to DB + conn <- RODBC::odbcConnectAccess2007(filename) + ## 4.3. Table names + tables_vec <- RODBC::sqlTables(conn) |> + dplyr::filter(TABLE_TYPE != "SYSTEM TABLE") |> + dplyr::pull(TABLE_NAME) + ## 4.4. Read data into a list data_lst <- purrr::map( .x = tables_vec, - .f = \(x) DBI::dbReadTable(conn, x) |> + .f = \(x) RODBC::sqlFetch(conn, x) |> tibble::as_tibble() ) - ## 4.6. Rename list + ## 4.5. Disconnect from DB + RODBC::odbcClose(conn) + ## 4.5. Rename list names(data_lst) <- tables_vec - ## 4.7. Convert IFN4 PCDatosMap to projected SF (only in field database) + ## 4.6. Convert IFN4 PCDatosMap to projected SF (only in field database) ## -> IFN3 doesn't have huso column if (ifn == 4 & database == "field") { data_lst$PCDatosMap_sf <- sf::st_as_sf( diff --git a/cran-comments.md b/cran-comments.md index fa2104a..858617d 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,5 +1,5 @@ ## R CMD check results -0 errors | 0 warnings | 0 note - +0 errors | 0 warnings | 1 note +* This is a new release.