Skip to content

Commit 429e174

Browse files
committed
Updated method for extracting transect names from filenames in extract_csv().
1 parent d0fc139 commit 429e174

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

R/utils.R

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ extract_csv <- function(filename) {
99
tmp <- data.table::fread(filename, sep = ",")
1010

1111
# Extract transect name from the file name
12-
transect <- tail(unlist(stringr::str_split(filename, "/")), n = 1) %>%
13-
stringr::str_split("_") %>%
14-
purrr::pluck(1, 2)
12+
# New method using regex, to better handle variations in filenames
13+
tranect <- stringr::str_extract(filename, pattern = "\\d{3}(-\\d+)?\\b")
14+
15+
# Original method, which failed when names weren't properly separated by underscores
16+
# transect <- tail(unlist(stringr::str_split(filename, "/")), n = 1) %>%
17+
# stringr::str_split("_") %>%
18+
# purrr::pluck(1, 2)
1519

1620
# Are data from CPS?
1721
is.cps <- ifelse(stringr::str_detect(filename, "CPS"), TRUE, FALSE)

0 commit comments

Comments
 (0)