To find the extension of a csv file in R, you can use regular expressions with string manipulation functions. For example:
213 chars9 lines
This code will output "csv", which is the extension of the provided file name "data_file.csv".
The sub()
function is used to replace a regular expression pattern with a replacement string, and it uses .*\\.
to match any characters before the period (which is escaped with \ to treat it as a literal period rather than a regular expression wildcard) that precedes the file extension. The \\1
in the replacement string represents the captured group in the pattern, which is the file extension.
gistlibby LogSnag