Skip to content

Commit

Permalink
revert RODBC
Browse files Browse the repository at this point in the history
  • Loading branch information
Cidree committed Oct 11, 2024
1 parent 79201e1 commit 5a288b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ Collate:
'pathogens.R'
Suggests:
aws.s3,
DBI,
giscoR,
RODBC,
odbc,
testthat (>= 3.0.0)
Config/testthat/edition: 3
URL: https://cidree.github.io/forestdata/
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

- 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.
Expand Down
28 changes: 15 additions & 13 deletions R/forest-inventory.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ fd_inventory_spain <- function(province,
path_metadata = NULL,
quiet = FALSE) {
# 0. Handle errors
if (!requireNamespace("RODBC", quietly = TRUE)) stop("Package `RODBC` is required to access the inventory data. Please, install it.")
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.")
# 1. Filter province
## 1.1. Fix province
province_fix <- province |>
Expand Down Expand Up @@ -318,23 +319,24 @@ fd_inventory_spain <- function(province,
## 4.1. File name
filename <- list.files(dir_unzip, full.names = TRUE, pattern = "\\.accdb$")
## 4.2. Connect to DB
## 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
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
data_lst <- purrr::map(
.x = tables_vec,
.f = \(x) RODBC::sqlFetch(conn, x) |>
.f = \(x) DBI::dbReadTable(conn, x) |>
tibble::as_tibble()
)
## 4.5. Disconnect from DB
RODBC::odbcClose(conn)
## 4.5. Rename list
## 4.6. Rename list
names(data_lst) <- tables_vec
## 4.6. Convert IFN4 PCDatosMap to projected SF (only in field database)
## 4.7. 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(
Expand Down
4 changes: 2 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note
0 errors | 0 warnings | 0 note


* This is a new release.

0 comments on commit 5a288b1

Please sign in to comment.