我在自动化我的.R文件时遇到了很多困难,而且我也很难理解有关它的信息。但这就是:
我使用windows 7,只想每天早上8点自动运行一个R.script。.R文件本身就会发出输出,所以我不想要单独的输出文件。我创建了这样一个蝙蝠文件:
"C:\R\R-3.0.1\bin\x64\Rscript.exe" "C:\R\R-3.0.1\bin\x64\Scripts\24AR_v1bat.R"
Echo %DATE% %TIME% %ERRORLEVEL% >> C:\R\R-3.0.1\bin\x64\scripts\24AR_v1.txt当我手动运行它时,它运行得非常完美。两者都有/没有:
--default-packages=list当我通过cmd窗口运行它时,它工作得很好。然而,当我试图通过任务调度程序运行它时,它会运行,但不起作用。(我要么在错误消息文件中得到一个1或2个错误)。
我看过R简介--从命令行调用R,并帮助(Rscript),但我仍然无法使它工作。
新编辑:我发现不执行MS调用,会让我的代码从调度程序中运行。不知道我是该问个新问题还是?
编辑:添加R-脚本
# 24 Hour AR-model, v1 ----------------------------------------------------
#Remove all variables from the workspace
#rm(list=ls())
# Loading Packages
library(forecast)
#Get spot-prices System from 2012-01-01 to today
source("/location/Scripts/SQL_hourlyprices.R")
sys <- data.frame()
sys <- spot
rm(spot)
# Ordering the data, first making a matrix with names: SYS
colnames(sys) <- c("date","hour","day","spot")
hour <-factor(sys[,2])
day <-factor(sys[,3])
dt<-sys[,1]
dt<-as.Date(dt)
x<-sys[,4]
q <-ts(x, frequency=24)
x0<- q[hour==0]
x1<- q[hour==1]
x0 <-ts(x0, frequency=7)
x1 <-ts(x1, frequency=7)
# ARIMA MODELS
y0<-Arima(x0,order=c(2,1,0))
y1<-Arima(x1,order=c(2,1,1))
fr0 <- forecast.Arima(y0,h=1)
fr1 <- forecast.Arima(y1,h=1)
h1<-as.numeric(fr0$mean)
h2<-as.numeric(fr1$mean)
day1 <-Sys.Date()+1
atable<-data.frame
runtime<-Sys.time()
atable<-cbind(runtime,day1,h1,h2)
options(digits=4)
write.table(atable, file="//location/24ar_v1.csv",
append=TRUE,quote=FALSE, sep=",", row.names=F, col.names=F)但是正如我所说的,我可以用批处理文件手动运行代码,并让它完美地工作,但是使用调度器它就不能工作了。
发布于 2013-08-16 06:11:42
经过几个小时的尝试,问题似乎是:
source("/location/Scripts/SQL_hourlyprices.R")我只是在里面有一个SQL调用:
sqlQuery(dbdata2, "SELECT CONVERT(char(10), [lokaldatotid],126) AS date,
DATEPART(HOUR,lokaldatotid) as hour,
DATENAME(DW,lokaldatotid) as dag,
pris as spot
FROM [SpotPriser] vp1
WHERE (vp1.boers_id=0)
AND (vp1.omraade_id=0)
AND lokaldatotid >='2012-01-01'
GROUP BY lokaldatotid, pris
ORDER BY lokaldatotid, hour desc") -> spot当我将它直接移到脚本中并删除源行时,脚本将与调度程序一起运行。
我不知道为什么..。
https://stackoverflow.com/questions/18230662
复制相似问题