Learn R Programming

googleCloudRunner (version 0.2.0)

cr_deploy_r: Deploy an R script with an optional schedule

Description

Will create a build to run an R script in Cloud Build with an optional schedule from Cloud Scheduler

Usage

cr_deploy_r(
  r,
  schedule = NULL,
  source = NULL,
  run_name = NULL,
  r_image = "rocker/verse",
  pre_steps = NULL,
  post_steps = NULL,
  timeout = 600L,
  ...,
  email = cr_email_get(),
  region = cr_region_get(),
  projectId = cr_project_get(),
  launch_browser = interactive()
)

Arguments

r

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

schedule

A cron schedule e.g. "15 5 * * *"

source

A Source object specifying the location of the source files to build, usually created by cr_build_source

run_name

What name the R code will identify itself as. If NULL one is autogenerated.

r_image

The R docker environment executing the R code

pre_steps

Other cr_buildstep to run before the R code executes

post_steps

Other cr_buildstep to run after the R code executes

timeout

Amount of time that this build should be allowed to run, to second

...

Other arguments passed through to cr_buildstep_r

email

The email that will authenticate the job set via cr_email_set

region

The region usually set with cr_region_set

projectId

ID of the project

launch_browser

Whether to launch the logs URL in a browser once deployed

Value

If scheduling then a Job, if building immediately then a Build

Details

If schedule=NULL then the R script will be run immediately on Cloud Build via cr_build.

If schedule carries a cron job string (e.g. "15 5 * * *") then the build will be scheduled via Cloud Scheduler to run as described in cr_build_schedule_http

The R script will execute within the root directory of which Source you supply, usually created via cr_build_source. Bear in mind if the source changes then the code scheduled may need updating.

The r_image dictates what R libraries the R environment executing the code of r will have, via the underlying Docker container usually supplied by rocker-project.org. If you want custom R libraries beyond the default, create a docker container with those R libraries installed (perhaps via cr_deploy_docker)

See Also

If you want to run R code upon certain events like GitHub pushes, look at cr_buildtrigger

Other Deployment functions: cr_deploy_docker(), cr_deploy_git_html(), cr_deploy_github_docker(), cr_deploy_packagetests(), cr_deploy_pkgdown(), cr_deploy_run()

Examples

Run this code
# NOT RUN {
r_lines <- c("list.files()",
             "library(dplyr)",
             "mtcars %>% select(mpg)",
             "sessionInfo()")
source <- cr_build_source(RepoSource("googleCloudStorageR",
                                     branchName = "master"))

# }
# NOT RUN {
cr_project_set("my-project")
cr_region_set("europe-west1")
cr_email_set("123456@projectid.iam.gserviceaccount.com")

# check the script runs ok
cr_deploy_r(r_lines, source = source)

# schedule the script
cr_deploy_r(r_lines, schedule = "15 21 * * *", source = source)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab