Skip to content

Commit

Permalink
fix read_meso
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Sep 4, 2024
1 parent 4afe7ab commit 4e58acb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions r-package/R/read_meso_region.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ read_meso_region <- function(code_meso = "all",
y <- code_meso

# input "all"
if(code_meso=="all"){
if (code_meso=="all" | nchar(code_meso)==2) {

# abbrev_state
} else if(code_meso %in% temp_sf$abbrev_state){
temp_sf <- subset(temp_sf, abbrev_state == y)

# code_state
} else if(code_meso %in% temp_sf$code_state){
temp_sf <- subset(temp_sf, code_state == y)
# # abbrev_state
# } else if (code_meso %in% temp_sf$abbrev_state){
# temp_sf <- subset(temp_sf, abbrev_state == y)
#
# # code_state
# } else if (code_meso %in% substring(temp_sf$code_meso,1,2)) {
# temp_sf <- subset(temp_sf, substring(code_meso,1,2) == y)

# code_meso
} else if(code_meso %in% temp_sf$code_meso){
} else if (code_meso %in% temp_sf$code_meso) {
temp_sf <- subset(temp_sf, code_meso == y)

} else {stop(paste0("Error: Invalid Value to argument 'code_meso'",collapse = " "))}
Expand Down
3 changes: 3 additions & 0 deletions r-package/tests/testthat/test-read_meso_region.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ test_that("read_meso_region", {
expect_true(is(read_meso_region(code_meso="AC", year=2010), "sf"))
# expect_true(is(read_meso_region(code_meso=11, year=2010), "sf"))
expect_true(is(read_meso_region(code_meso="all", year=2010) , "sf"))
expect_true(is(read_meso_region(code_meso=12, year=2017) , "sf"))
expect_true(is(read_meso_region(code_meso="AM", year=2000) , "sf"))


test_meso_code <- read_meso_region(code_meso=1401, year=2010)

Expand Down

0 comments on commit 4e58acb

Please sign in to comment.