Hi is there a way to import a csv file that gets exported to my downloads folder daily.
Basically I need to import the csv file daily and change some information on it and then export new csv file. Cani do this with out having to change the file name in the read.csv path?
If you have multiple files with, say, the same prefix but a different suffix each day (for example, "myfile_20200430.csv", "myfile_20200501.csv", etc.) you can identify and load the the most recent file in the sequence as follows:
# Function to identify the most recent file with a given name pattern
# in a given folder
# mtime is the date when the file was last modified. You could change this
# to ctime to identify the latest file by the most recent creation date.
latest_file = function(fpattern, fpath) {
f = list.files(pattern=fpattern, path=fpath, full.names=TRUE)
f = file.info(f)
rownames(f)[which.max(f$mtime)]
}
myfile = latest_file(fpattern="myfile.*csv", fpath="~/downloads")
d = readr::read_csv(myfile)