Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 永久保存googleway API密钥_R_Googleway - Fatal编程技术网

R 永久保存googleway API密钥

R 永久保存googleway API密钥,r,googleway,R,Googleway,有没有办法将API密钥永久保存到我的R配置文件或环境中,这样我就不必每次会话都使用set\u key()?我不喜欢在我的代码中保存密钥,因为它位于github上。您可以将它放在第一个功能中,该功能位于Rprofile.site文件中 我不确定你在哪个平台上,但这应该可以 rfile <- list.files(path = Sys.getenv("R_HOME"), recursive = TRUE, full.names = TRUE, patt

有没有办法将API密钥永久保存到我的R配置文件或环境中,这样我就不必每次会话都使用
set\u key()?我不喜欢在我的代码中保存密钥,因为它位于github上。

您可以将它放在
第一个功能中,该功能位于
Rprofile.site
文件中

我不确定你在哪个平台上,但这应该可以

rfile <- list.files(path = Sys.getenv("R_HOME"), recursive = TRUE, 
                    full.names = TRUE, pattern = "Rprofile.site")
file.edit(rfile)
保存文件并重新启动R

编辑 如果您的api密钥是一个
令牌
对象,如oauth,只需保存到一个文件中,读入并分配给
google\u api\u密钥
值。例如:

.First <- function(){
  # Your oauth api key read in from file
  google_api_key <- readRDS("~/.hide_google_token.rds")
  # Use assign to explicitly set the environment in which to populate the key
  assign("google_oauth_token", google_api_key, envir = .GlobalEnv)
}

.First您可以将其放入
First
函数中,该函数位于
Rprofile.site
文件中

我不确定你在哪个平台上,但这应该可以

rfile <- list.files(path = Sys.getenv("R_HOME"), recursive = TRUE, 
                    full.names = TRUE, pattern = "Rprofile.site")
file.edit(rfile)
保存文件并重新启动R

编辑 如果您的api密钥是一个
令牌
对象,如oauth,只需保存到一个文件中,读入并分配给
google\u api\u密钥
值。例如:

.First <- function(){
  # Your oauth api key read in from file
  google_api_key <- readRDS("~/.hide_google_token.rds")
  # Use assign to explicitly set the environment in which to populate the key
  assign("google_oauth_token", google_api_key, envir = .GlobalEnv)
}
。首先