我有一個'R'文件,它插入從數據庫中讀取數據,執行一些計算,然後將數據重新插入表中。R腳本.bat文件 - 執行前添加源文件
之前,我執行腳本,我跑「源」,如下..
我想使用Windows任務計劃程序自動調度此腳本運行。我下面的指導https://trinkerrstuff.wordpress.com/2015/02/11/scheduling-r-tasks-via-windows-task-scheduler/ - 當創建.bat文件就應該是這個樣子:
echo off
CMD BATCH C:\PATHNAME\RSCRIPT.R
,我應該插入什麼位置,以確保它運行的「來源」第一?
在R代碼,我
在代碼中我有:
#use a relative path to locate our common utilities file and source it
source("..//R-Utilities//Utilities.R")
# use check_install_package function from Utilities.R to install and load
packages
check_install_package("lubridate")
check_install_package("plyr")
check_install_package("dplyr")
check_install_package("dtplyr")
check_install_package("ISOweek")
check_install_package("stringi")
check_install_package("RODBC")
#give us access to the library of functions this script uses
source("CTB_functions.R")
但我需要運行我的整個代碼之前單擊源按鈕,或者我得到一個錯誤(如下) 。
> #this automatically sets the working directory to be where this file is
> setwd(getSrcDirectory(function(x) {x}))
Error in setwd(getSrcDirectory(function(x) { :
cannot change working directory
>
> #use a relative path to locate our common utilities file and source it
> source("../R-Utilities/Utilities.R")
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file '../R-Utilities/Utilities.R': No such file or directory
>
> # use check_install_package function from Utilities.R to install and load
packages
> check_install_package("lubridate")
Error: could not find function "check_install_package"
> check_install_package("plyr")
Error: could not find function "check_install_package"
> check_install_package("dplyr")
Error: could not find function "check_install_package"
> check_install_package("dtplyr")
Error: could not find function "check_install_package"
> check_install_package("ISOweek")
Error: could not find function "check_install_package"
> check_install_package("stringi")
Error: could not find function "check_install_package"
> check_install_package("RODBC")
Error: could not find function "check_install_package"
>
> #give us access to the library of functions this script uses
> source("CTB_functions.R")
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'CTB_functions.R': No such file or directory
您可以將'source()'命令添加到您的腳本以獲取文件。不確定這些文件中究竟是什麼,很難準確地告訴你在做什麼。 – MrFlick
我已經添加了一些代碼可能有幫助 – SwiftBeginner