Skip to content

Commit

Permalink
changes from using rappdirs::user_cache_dir to tools::R_user_dir to a…
Browse files Browse the repository at this point in the history
…ppease cran and fixed a few minor tests. Issue #403
  • Loading branch information
djhocking committed Nov 10, 2021
1 parent 57a1453 commit 0ba86af
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 16 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ License: MIT + file LICENSE
Encoding: UTF-8
Language: en-US
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut","cre"),
person("Scott", "Chamberlain", role = c("aut"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-1444-9135")),
person("Daniel", "Hocking", role = c("ctb","cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-1889-9184")),
person("Brooke", "Anderson", role = "ctb"),
person("Maëlle", "Salmon", role = "ctb"),
person("Adam", "Erickson", role = "ctb"),
Expand Down
10 changes: 5 additions & 5 deletions R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ check_response <- function(x){
} else {
if (
class(try(out$results, silent = TRUE)) == "try-error" ||
is.null(try(out$results, silent = TRUE))
is.null(try(out$results, silent = TRUE))
) {
warning("Sorry, no data found", call. = FALSE)
}
Expand Down Expand Up @@ -174,7 +174,7 @@ safe_read_csv <- function(x, header = TRUE, stringsAsFactors = FALSE, sep = ",",
assert(x, "character")

tmp <- tryCatch(
data.table::fread(x, header = header, sep = sep,
data.table::fread(x, header = header, sep = sep,
stringsAsFactors = stringsAsFactors, data.table = FALSE,
colClasses = col_types),
error = function(e) e,
Expand All @@ -197,13 +197,13 @@ check_lcd_columns <- function(x) {
allowable_types <- c("character", "integer", "numeric", "factor", "integer64", "POSIXct")
allowed <- x %in% allowable_types
if(FALSE %in% allowed) {
message <- paste0(names(x[which(!(allowed))]),
message <- paste0(names(x[which(!(allowed))]),
" must equal a valid R class ('character', 'integer', 'numeric', 'factor', 'integer64', 'POSIXct')",
collapse = "\n")} else {
message <- NULL }
}
return(message)

}


Expand All @@ -226,7 +226,7 @@ is_windows <- function() {
.Platform$OS.type == "windows"
}

rnoaa_cache_dir <- function() rappdirs::user_cache_dir("rnoaa")
rnoaa_cache_dir <- function() tools::R_user_dir("rnoaa", which = "cache")

assert_range <- function(x, y) {
if (!x %in% y) {
Expand Down
1 change: 1 addition & 0 deletions man/lcd_columns.Rd

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

2 changes: 1 addition & 1 deletion man/rnoaa_caching.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
library(testthat)
test_check("rnoaa")
test_check("rnoaa")
2 changes: 1 addition & 1 deletion tests/testthat/test-check_response.r
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_that("check_response works correctly on bad response content-type", {
expect_error(
ncdc(datasetid='GHCND', stationid='GHCND:USW00014895',
startdate = '2013-10-01', enddate = '2013-12-01'),
"wrong response type"
"wrong response type, open an issue"
)
webmockr::disable()
})
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-lcd.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ test_that("lcd", {

expect_is(aa, "tbl_df")

expect_type(aa$station, 'integer')
expect_type(aa$station, c('character'))
expect_type(aa$date, 'double')
expect_type(aa$latitude, 'double')
expect_type(aa$longitude, 'double')
expect_type(aa$elevation, 'double')
expect_type(aa$hourlysealevelpressure, 'double')
expect_type(aa$hourlysealevelpressure, 'character')
})

test_that("lcd fails well", {
Expand All @@ -41,7 +41,7 @@ test_that("lcd fails well", {
expect_error(lcd(5, list(1)),
"year must be of class")
expect_error(lcd(station = "01338099999", year = 2017, col_types = list(1)),
"col_types must be of class")
"col_types must be a")
})

test_that("lcd fails well when trying to read a bad file", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_that("safe_read_csv",{
expect_is(safe_read_csv, "function")
expect_error(safe_read_csv())
expect_error(safe_read_csv(5), "class")

# file doesn't exist, throws warning on read.csv
file1 <- tempfile()
expect_error(safe_read_csv(file2))
Expand All @@ -20,8 +20,8 @@ test_that("safe_read_csv",{
# with csv data
file4 <- tempfile()
writeLines("A,B,SOURCE\n1,2,3", con = file(file4))
expect_is(safe_read_csv(file4), "data.frame")
expect_is(safe_read_csv(file4, col_types = NULL), "data.frame")

# cleanup
invisible(lapply(c(file1, file2, file3, file4), unlink))
})
2 changes: 1 addition & 1 deletion vignettes/rnoaa.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ b) Alternatively, you might find it easier to set this as an option, either by a
options(noaakey = "KEY_EMAILED_TO_YOU")
```

c) You can always store in permamently in your `.Rprofile` file.
c) You can always store in permanently in your `.Rprofile` file.

### Fetch list of city locations in descending order

Expand Down

0 comments on commit 0ba86af

Please sign in to comment.