Helper to run R code within build steps, from either an existing local R file or within the source of the build.
R code to run or a file containing R code ending with .R, or the gs:// location on Cloud Storage of the R file you want to run
The docker image that will run the R code, usually from rocker-project.org
Whether the R code will be from a runtime file within the source or at build time copying over from a local R file in your session
prefixed to name - set to "" to suppress. Will be suppressed if name
starts with gcr.io or *-docker.pkg.dev
Default TRUE. This will turn $
into $$
within the script to avoid them being recognised as Cloud Build variables. Turn this off if you want that behaviour (e.g. my_project="$PROJECT_ID"
)
Optional arguments for the R script run by Rscript
.
should `Rscript` be run or `R`?
Other arguments passed to cr_buildstep
If r_source="runtime"
then r
should be the location of that file within the source or image
that will be run by the R code from image
If r_source="local"
then it will copy over from a character string or local file into the build step directly.
If the R code location starts with gs://
then an extra buildstep will be added that will download the R script from that location then run it as per r_source="runtime"
. This will consequently override your setting of r_source
Other Cloud Buildsteps:
cr_buildstep_bash()
,
cr_buildstep_decrypt()
,
cr_buildstep_df()
,
cr_buildstep_docker()
,
cr_buildstep_edit()
,
cr_buildstep_extract()
,
cr_buildstep_gcloud()
,
cr_buildstep_gitsetup()
,
cr_buildstep_mailgun()
,
cr_buildstep_nginx_setup()
,
cr_buildstep_packagetests()
,
cr_buildstep_pkgdown()
,
cr_buildstep_run()
,
cr_buildstep_secret()
,
cr_buildstep_slack()
,
cr_buildstep_targets()
,
cr_buildstep()
cr_project_set("my-project")
#> ℹ 2022-03-26 19:55:52 > ProjectId set to my-project
#> [1] "my-project"
cr_bucket_set("my-bucket")
#> ℹ 2022-03-26 19:55:53 > Bucket set to my-bucket
#> [1] "my-bucket"
# create an R buildstep inline
cr_buildstep_r(c("paste('1+1=', 1+1)", "sessionInfo()"))
#> [[1]]
#> ==cloudRunnerBuildStep==
#> name: rocker/r-base
#> args:
#> - Rscript
#> - -e
#> - |-
#> paste('1+1=', 1+1)
#> sessionInfo()
#>
if (FALSE) {
# create an R buildstep from a local file
cr_buildstep_r("my-r-file.R")
# create an R buildstep from a file within the source of the Build
cr_buildstep_r("inst/schedule/schedule.R", r_source = "runtime")
# create an R buildstep with Rscript arguments and use a large
# machine with 32 cores
## create storage source
storage_source <- cr_build_upload_gcs(
"my-r-script.R"
)
## create the buildstep with the R script
step1 <- cr_buildstep_r("deploy/my-r-script.R",
r_source = "runtime",
rscript_args = c("args_1=<args1>", "args_2=<args_2>")
)
## run the script on Cloud Build
cr_build(
cr_build_yaml(
steps = step1
),
source = storage_source,
options = list(machineType = "E2_HIGHCPU_32")
)
}
# use a different Rocker image e.g. rocker/verse
cr_buildstep_r(c(
"library(dplyr)",
"mtcars %>% select(mpg)",
"sessionInfo()"
),
name = "verse"
)
#> [[1]]
#> ==cloudRunnerBuildStep==
#> name: rocker/verse
#> args:
#> - Rscript
#> - -e
#> - |-
#> library(dplyr)
#> mtcars %>% select(mpg)
#> sessionInfo()
#>
# use your own R image with custom R
my_r <- c("devtools::install()", "pkgdown::build_site()")
br <- cr_buildstep_r(my_r, name = "gcr.io/gcer-public/packagetools:latest")