knitr::opts_chunk$set(echo = TRUE)
A custom function for calling gcloud
SDK from Rmarkdown via OS command system2()
Create function for calling gcloud
SDK from Rmarkdow:
library(withr) library(glue) sh <- function(cmd, args = c(), intern = FALSE) { with_path(path.expand("~/google-cloud-sdk/bin/"), { if (is.null(args)) { cmd <- glue(cmd) s <- strsplit(cmd, " ")[[1]] cmd <- s[1] args <- s[2:length(s)] } ret <- system2(cmd, args, stdout = TRUE, stderr = TRUE) if ("errmsg" %in% attributes(attributes(ret))$names) cat(attr(ret, "errmsg"), "\n") if (intern) return(ret) else cat(paste(ret, collapse = "\n")) })}
Authenticate with Google Cloud and Vertex AI via googleAuthR
package and googleCloudVertexAIR
:
library(googleAuthR) library(googleCloudVertexAIR) options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/cloud-platform") gar_auth_service(json_file = Sys.getenv("GAR_SERVICE_JSON"))
Set gcloud
project:
sh("gcloud config set project {gcva_project_get()}")
List gcloud
configuration to verify:
sh("gcloud config list")
Special thanks to [Fabian Hirschmann](https://github.com/fhirschmann, the original author of this source code.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.