R スクリプトを開始するバッチ ファイルがあります。
"C:\Program Files\R\R-3.3.1\bin\x64\Rscript.exe" "C:\Folder\Script.R"
この R スクリプト内で、gs_auth
関数を使用して認証トークンを取得し、R セッションで使用します。フォルダー エクスプローラーからバッチ ファイルをダブルクリックすると、R スクリプトを正常に実行でき、すべてが完全に実行されます。
タスク スケジューラ タスクを設定してバッチ ファイルを実行すると、代わりに次のエラーが表示されます。
Error in httpuv::startServer(use$host, use$port, list(call = listen)) :
Failed to create server
Calls: gs_title ... init_oauth2.0 -> oauth_authorize -> oauth_listener -> <Anonymous>
Execution halted
タスク スケジューラで「最上位の特権で実行」を試み、Windows パスワードも入力しましたが、何も機能しないようです。
トークンの読み込みに関して何か不足していますか?
コード
コメントアウトされた行は、後で使用できるようにトークンを「焼き付ける」ための初期化手順を示しているためです。これらの手順は、こちらに従って行われました。
##Need to run gs_auth line only because need to paste stuff in from IE
#token <- gs_auth(cache = FALSE)
#gd_token()
##Bake token to working directory
#saveRDS(token, file = "googlesheets_token.rds")
setwd("C:/Folder")
gs_auth(token = "googlesheets_token.rds")
for_gs <- gs_title("data_log")
for_gs_sheet <- gs_read(for_gs)
XML:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2018-08-18T15:11:51.0347984</Date>
<Author>abc-PC\User</Author>
<URI>\ozb</URI>
</RegistrationInfo>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-2866463773-2659414307-4023886308-1002</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<Enabled>false</Enabled>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
</Settings>
<Triggers>
<CalendarTrigger>
<StartBoundary>2018-08-18T15:00:00</StartBoundary>
<Repetition>
<Interval>PT15M</Interval>
</Repetition>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Actions Context="Author">
<Exec>
<Command>"C:\Folder\run_it.bat"</Command>
</Exec>
</Actions>
</Task>