Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Error in today() : could not find function "today"

Tags:

r

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
like image 601
Michael T Johnson Avatar asked Oct 23 '25 09:10

Michael T Johnson


2 Answers

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).

like image 83
Gregor Thomas Avatar answered Oct 25 '25 01:10

Gregor Thomas


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

like image 40
Fino Avatar answered Oct 25 '25 01:10

Fino