I've been using the here
package to make my projects more portable. It works great apart from when I use cronR
to schedule some of my scripts. When I run my_script.R
from Rstudio I get a message from library(here)
:
here() starts at /home/pd/projects/my_proj
When I set script.R
to run using cronR
I get a different message:
here() starts at /home/pd
Which is where my_schedule.cron
is stored. Ideally I want to keep my_schedule.cron
where it is. I can see from the logs that my_script.R
runs fine apart from when it comes to saving data because the path used by here()
is incorrect. Is there anyway to get the here
function to detect the project dir when my_script.R
is run from cronR
or the terminal?
You can modify the command cmd
that is usually created with cron_rscript()
by adding cd
to your project folder followed by the usual part:
cmd <- "cd /home/pd/projects/my_proj && /usr/lib/R/bin/Rscript ./my_script.R >> ./my_script.log 2>&1"
cron_add(command = cmd, frequency = 'daily', at = '18:00')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With