Skip to content

Commit

Permalink
Merge branch 'master' of github.com:luckinet/tabshiftr
Browse files Browse the repository at this point in the history
  • Loading branch information
EhrmannS committed Dec 22, 2023
2 parents 5dca504 + 63a945b commit eb80422
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/getIDVars.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ getIDVars <- function(schema = NULL, input = NULL){
# need to distinguish between one and several columns
if(dim(temp)[2] == 1){
temp <- temp %>%
extract(col = 1, into = names(temp), regex = paste0("(", tempVar$split, ")"))
extract(col = 1, into = names(temp), regex = tempVar$split)
} else {
temp <- map_dfc(.x = seq_along(temp), .f = function(iy){
temp %>%
select(all_of(iy)) %>%
extract(col = 1, into = names(temp)[iy], regex = paste0("(", tempVar$split, ")"))
extract(col = 1, into = names(temp)[iy], regex = tempVar$split)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-02_column_mismatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ test_that("split a column that contains several identifying variables in one col

schema <-
setIDVar(name = "territories", columns = 1) %>%
setIDVar(name = "year", columns = 2, split = ".+?(?=_)") %>%
setIDVar(name = "commodities", columns = 2, split = "(?<=\\_).*") %>%
setIDVar(name = "year", columns = 2, split = "(.+?(?=_))") %>%
setIDVar(name = "commodities", columns = 2, split = "((?<=\\_).*)") %>%
setObsVar(name = "harvested", columns = 4) %>%
setObsVar(name = "production", columns = 5)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-03_wide_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("wide variable (that needs to be split) in first row of header", {
schema <-
setIDVar(name = "territories", columns = 1) %>%
setIDVar(name = "year", columns = 3) %>%
setIDVar(name = "commodities", columns = c(4, 6), rows = 1, split = ".+?(?=_)") %>%
setIDVar(name = "commodities", columns = c(4, 6), rows = 1, split = "(.+?(?=_))") %>%
setObsVar(name = "harvested", columns = c(4, 6), top = 2) %>%
setObsVar(name = "production", columns = c(5, 7), top = 2)

Expand Down

0 comments on commit eb80422

Please sign in to comment.