File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,12 @@ extract_csv <- function(filename) {
9
9
tmp <- data.table :: fread(filename , sep = " ," )
10
10
11
11
# 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]$" , " " )
14
18
15
19
# Original method, which failed when names weren't properly separated by underscores
16
20
# transect <- tail(unlist(stringr::str_split(filename, "/")), n = 1) %>%
You can’t perform that action at this time.
0 commit comments