Skip to content

Commit

Permalink
fixing rcmdcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Nov 5, 2024
1 parent d45c14b commit e78102c
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 135 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(geocode)
export(geocodebr_cache)
export(set_geocodebr_cache_dir)
importFrom(data.table,"%chin%")
importFrom(data.table,"%like%")
importFrom(data.table,":=")
importFrom(data.table,.GRP)
importFrom(data.table,.I)
Expand Down
6 changes: 3 additions & 3 deletions R/download_cnefe.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#' download_cnefe(abbrev_state = c("AC", "AL", "RJ"),
#' showProgress = FALSE)
#'
#' # download CNEFE for all states
#' download_cnefe(abbrev_state = "all",
#' showProgress = FALSE)
#' # # download CNEFE for all states
#' # download_cnefe(abbrev_state = "all",
#' # showProgress = FALSE)
#'
download_cnefe <- function(abbrev_state = NULL,
showProgress = TRUE,
Expand Down
18 changes: 11 additions & 7 deletions R/geocode.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
#' Download microdata of population records from Brazil's census. Data collected
#' in the sample component of the questionnaire.
#'
#' @template year
#' @template columns
#' @template add_labels
#' @param input_table A data frame.
#' @param logradouro A string.
#' @param numero A string.
#' @param complemento A string.
#' @param cep A string.
#' @param bairro A string.
#' @param municipio A string.
#' @param estado A string.
#' @template showProgress
#' @param output_simple Logic. Defaults to `TRUE`
#' @param ncores Number of cores to be used in parallel execution. Defaults to
Expand All @@ -17,13 +22,12 @@
#' @export
#' @family Microdata
#' @examplesIf identical(tolower(Sys.getenv("NOT_CRAN")), "true")
#' library(geocodebr)
#'
#' # open input data
#' data_path <- system.file("extdata/sample_1.csv", package = "geocodebr")
#' input_df <- read.csv(data_path)
#'
#' df <- geocodebr::geocode_duck(
#' df <- geocodebr::geocode(
#' input_table = input_df,
#' logradouro = "nm_logradouro",
#' numero = "Numero",
Expand Down Expand Up @@ -194,8 +198,8 @@ geocode <- function(input_table,

# start progress bar
if (isTRUE(showProgress)) {
total_n <- nrow(input_df)
pb <- txtProgressBar(min = 0, max = total_n, style = 3)
total_n <- nrow(input_table)
pb <- utils::txtProgressBar(min = 0, max = total_n, style = 3)
}

## CASE 1 --------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion R/geocodebr.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @aliases geocodebr-package
#'
#' @importFrom dplyr mutate select across case_when all_of
#' @importFrom data.table := .I .SD %chin% .GRP .N
#' @importFrom data.table := .I .SD %chin% .GRP .N %like%
#'
#' @keywords internal
"_PACKAGE"
Expand Down
25 changes: 1 addition & 24 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,6 @@ add_precision_col <- function(con, update_tb = NULL, precision = NULL){
}













#' Merge results of spatial coordinates and precision info for output
#'
#' @param con A db connection
#' @param x String. Name of a table written in con
#' @param y String. Name of a table written in con
#' @param output_tb Name of the new table to be written in con
#' @param key_cols Vector. Vector with the names of columns to perform left join
#' @param precision Integer. An integer
#'
#' @return Writes the result of the left join as a new table in con
#'
#' @keywords internal
merge_results <- function(con, x, y, key_column, select_columns){

# x = 'output_db'
Expand Down Expand Up @@ -302,7 +279,7 @@ create_index <- function(con, tb, cols, operation, overwrite=TRUE){
sprintf("SELECT * FROM duckdb_indexes WHERE table_name = '%s';", tb)
)

if (nrow(i) > 0 & isFALSE(overwrite)) { return(null) }
if (nrow(i) > 0 & isFALSE(overwrite)) { return(NULL) }
if (nrow(i) > 0 & isTRUE(overwrite)) {
DBI::dbExecute(con, sprintf('DROP INDEX IF EXISTS %s',idx))
}
Expand Down
6 changes: 3 additions & 3 deletions man/download_cnefe.Rd

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

28 changes: 17 additions & 11 deletions man/geocode.Rd

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

28 changes: 0 additions & 28 deletions man/merge_results.Rd

This file was deleted.

74 changes: 37 additions & 37 deletions tests/testthat/test_geocodebr_cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,43 @@ testthat::skip_if_not_installed("arrow")

# Reading the data -----------------------

test_that("geocodebr_cache", {

# simply list files
testthat::expect_message( geocodebr_cache() )

## delete existing

# download
geocodebr::read_emigration(year = 2010, showProgress = FALSE, cache = TRUE)

# cache dir
pkgv <- paste0('geocodebr/data_release_', geocodebr_env$data_release)
cache_dir <- tools::R_user_dir(pkgv, which = 'cache')

# list cached files
files <- list.files(cache_dir, full.names = TRUE)
fname <- paste0('2010_emigration_',geocodebr_env$data_release, '.parquet')
fname_full <- files[grepl(fname, files)]

testthat::expect_true( file.exists(fname_full) )
testthat::expect_message( geocodebr_cache(delete_file = fname) )
testthat::expect_false( file.exists(fname_full) )

## delete ALL
geocodebr::read_emigration(year = 2010, showProgress = FALSE, cache = TRUE)
files <- list.files(cache_dir, full.names = TRUE)
fname <- paste0('2010_emigration_',geocodebr_env$data_release, '.parquet')
fname_full <- files[grepl(fname, files)]
testthat::expect_true( file.exists(fname_full) )
testthat::expect_message( geocodebr_cache(delete_file = 'all') )
geocodebr_cache(delete_file = 'all')
# testthat::expect_true( length(list.files(cache_dir)) == 0 )

# if file does not exist, simply print message
testthat::expect_message( geocodebr_cache(delete_file ='aaa') )

})
# test_that("geocodebr_cache", {
#
# # simply list files
# testthat::expect_message( geocodebr_cache() )
#
# ## delete existing
#
# # download
# geocodebr::read_emigration(year = 2010, showProgress = FALSE, cache = TRUE)
#
# # cache dir
# pkgv <- paste0('geocodebr/data_release_', geocodebr_env$data_release)
# cache_dir <- tools::R_user_dir(pkgv, which = 'cache')
#
# # list cached files
# files <- list.files(cache_dir, full.names = TRUE)
# fname <- paste0('2010_emigration_',geocodebr_env$data_release, '.parquet')
# fname_full <- files[grepl(fname, files)]
#
# testthat::expect_true( file.exists(fname_full) )
# testthat::expect_message( geocodebr_cache(delete_file = fname) )
# testthat::expect_false( file.exists(fname_full) )
#
# ## delete ALL
# geocodebr::read_emigration(year = 2010, showProgress = FALSE, cache = TRUE)
# files <- list.files(cache_dir, full.names = TRUE)
# fname <- paste0('2010_emigration_',geocodebr_env$data_release, '.parquet')
# fname_full <- files[grepl(fname, files)]
# testthat::expect_true( file.exists(fname_full) )
# testthat::expect_message( geocodebr_cache(delete_file = 'all') )
# geocodebr_cache(delete_file = 'all')
# # testthat::expect_true( length(list.files(cache_dir)) == 0 )
#
# # if file does not exist, simply print message
# testthat::expect_message( geocodebr_cache(delete_file ='aaa') )
#
# })


# ERRORS and messages -----------------------
Expand Down
42 changes: 21 additions & 21 deletions tests/testthat/test_set_geocodebr_cache_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ testthat::skip_if_not_installed("arrow")

# Reading the data -----------------------

test_that("set_geocodebr_cache_dir", {

# default
testthat::expect_message( set_geocodebr_cache_dir() )

# Set custom cache directory
tempd <- tempdir()
testthat::expect_message( set_geocodebr_cache_dir(path = tempd) )

# download
t <- read_emigration(year = 2010, showProgress = FALSE)

# check if file exists in custom dir
files <- list.files(tempd, full.names = TRUE)
fname <- paste0('2010_emigration_',geocodebr_env$data_release, '.parquet')
fname_full <- files[grepl(fname, files)]
testthat::expect_true( file.exists(fname_full) )

# back to default path
set_geocodebr_cache_dir(path = NULL)
})
# test_that("set_geocodebr_cache_dir", {
#
# # default
# testthat::expect_message( set_geocodebr_cache_dir() )
#
# # Set custom cache directory
# tempd <- tempdir()
# testthat::expect_message( set_geocodebr_cache_dir(path = tempd) )
#
# # download
# t <- read_emigration(year = 2010, showProgress = FALSE)
#
# # check if file exists in custom dir
# files <- list.files(tempd, full.names = TRUE)
# fname <- paste0('2010_emigration_',geocodebr_env$data_release, '.parquet')
# fname_full <- files[grepl(fname, files)]
# testthat::expect_true( file.exists(fname_full) )
#
# # back to default path
# set_geocodebr_cache_dir(path = NULL)
# })


# ERRORS and messages -----------------------
Expand Down

0 comments on commit e78102c

Please sign in to comment.