diff --git a/R/getIDVars.R b/R/getIDVars.R index db9b287..85d8529 100644 --- a/R/getIDVars.R +++ b/R/getIDVars.R @@ -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) }) } } diff --git a/tests/testthat/test-02_column_mismatch.R b/tests/testthat/test-02_column_mismatch.R index 2dfc8dd..58129a4 100644 --- a/tests/testthat/test-02_column_mismatch.R +++ b/tests/testthat/test-02_column_mismatch.R @@ -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) diff --git a/tests/testthat/test-03_wide_id.R b/tests/testthat/test-03_wide_id.R index e1a7a88..3388e62 100644 --- a/tests/testthat/test-03_wide_id.R +++ b/tests/testthat/test-03_wide_id.R @@ -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)