Skip to content

Commit e13c8ed

Browse files
committed
Further revised transect name/number extraction using regex.
1 parent 3b768fc commit e13c8ed

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

R/utils.R

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

1111
# Extract transect name from the file name
12-
# New method using regex, to better handle variations in filenames
13-
transect <- stringr::str_extract(filename, pattern = "\\d{3}(-\\d+)?\\b")
12+
# New method using regex, to better handle variations in file names
13+
transect <- stringr::str_extract(filename, pattern = "_\\d{3}[\\w\\d\\W]([\\d]{1})?") %>%
14+
# Replace leading underscore
15+
stringr::str_replace("_", "") %>%
16+
# Replace trailing special characters
17+
stringr::str_replace("[^a-zA-Z0-9]$", "")
1418

1519
# Original method, which failed when names weren't properly separated by underscores
1620
# transect <- tail(unlist(stringr::str_split(filename, "/")), n = 1) %>%

0 commit comments

Comments
 (0)