We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d0fc139 commit 429e174Copy full SHA for 429e174
R/utils.R
@@ -9,9 +9,13 @@ extract_csv <- function(filename) {
9
tmp <- data.table::fread(filename, sep = ",")
10
11
# 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)
+ # New method using regex, to better handle variations in filenames
+ tranect <- stringr::str_extract(filename, pattern = "\\d{3}(-\\d+)?\\b")
+
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)
19
20
# Are data from CPS?
21
is.cps <- ifelse(stringr::str_detect(filename, "CPS"), TRUE, FALSE)
0 commit comments