Import newest csv file in directory

前端 未结 3 1566
慢半拍i
慢半拍i 2021-01-14 16:47

Goal:
- Import the newest file (.csv) from a local directory into R

Goal Details:
- A csv file is uploaded to a folder dail

3条回答
  •  离开以前
    2021-01-14 17:26

    -- readfile.R --

    files <- file.info(list.files(directory))
    read.csv(rownames(files)[order(files$mtime)][nrow(files)])
    

    I'd put the above script in a cron job that runs every morning at a time when the file for the day will have been written. The below crontab runs it every morning at 8am.

    -- in crontab --

    0 8 * * *  Rscript readfile.R
    

    Read more about cron here.

提交回复
热议问题