I have an R script that just prints todays date. It runs just fine in Rstudio but when set as a task within a batch file it produces the following error
Warning message:
package 'dplyr' was built under R version 3.4.4
Loading required package: NLP
Warning message:
package 'tm' was built under R version 3.4.4
Error in today() : could not find function "today"
Execution halted
Here is the script:
library(rvest)
library(dplyr)
library(tm)
yesterday <- today()
yesterday <- gsub("-", "", yesterday, fixed=TRUE)
print(yesterday)
Batch File:
"C:\Program Files\R\R-3.4.2\bin\R.exe" CMD BATCH --vanilla --slave "C:\Users\mike\Desktop\Make_Task\TEST_YESTERDAY.R"
timeout /t 5
When you don't know where an R function comes from, I'd recommend searching rdocumentation.org for the name of the function. In these results, you can see that today is from the lubridate package.
Personally, I would recommend removing the external dependency by using the built-in Sys.Date() instead. But adding library(lubridate) to the top of your script should also work (assuming lubridate is installed).
The today() function is from the lubridate package. You probably loaded the package manually inside RStudio, so it's not in your code. Just add library(lubridate) to the beginning of your script and it should be fine.
Alternatively, you could also use Sys.Date() from r-base
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