2016-07-27 31 views
1

我想發送電子郵件在R的批次機制(稱爲「D:\ R \ R-3.2.5 \ bin \ i386 \ R」--internet2 CMD BATCH腳本。 R)。在圭政權下,所有的工作都很好。發送電子郵件使用圖書館gmailr批量機制下R

首先編輯:

gmail_auth(scope='full',secret_file = 'client_id.json') 

notification_email <- mime() %>% 
    to("[email protected]") %>% 
    from("[email protected]") %>% 
    subject("subject")) 
send_message(notification_email) 

,但有

Error:oauth_listener() needs an interactive environment. 

第二個編輯

沒有gmail_auth

notification_email <- mime() %>% 
     to("[email protected]") %>% 
     from("[email protected]") %>% 
     subject("subject")) 
    send_message(notification_email) 

也有

Error: oauth_listener() needs an interactive environment. 

回答

0

我解決了這個問題,從一些幫助:https://cran.r-project.org/web/packages/googlesheets/vignettes/managing-auth-tokens.html#where-do-tokens-live-in-between-r-sessions

您的工作目錄(setwd)在GUI和Rscript中需要相同。在運行gmail_auth之前,您必須將工作目錄設置爲令牌的位置。 (filename = .httr-oauth)。

wd <- "C:/My Working Directory/" 
setwd(wd) 
gmail_auth(scope='full',secret_file = 'client_id.json') 
  1. 在GUI添加setwd命令腳本
  2. 運行gmail_auth命令
  3. 選擇選項1提示時
  4. 保存腳本
  5. 運行在RSCRIPT
+0

謝謝!這工作! –