R Functions Framework
🅡 is a programming language and environment commonly used for statistical computing, data analytics and scientific research.
The R Functions Framework allows you to write portable R functions that can be easily deployed to Cloud Run.
In this blogpost, we’ll walk through deploying an R service to Cloud Run!
Install R
Install the precompiled binary distribution of R for your operating system at https://cloud.r-project.org/.
This will install the R language and rscript
CLI.
Install the R extension in VS Code
For easy local testing of R in our IDE, install the R extension from the VS Marketplace:
Test locally
Open the VS Code command palette (⌘⇧P) and type:
R: Run Command in Terminal
This will start an R Interactive session.
You’ll see this prompt:
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.Natural language support but running in an English localeR is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
In this session, install R devtools
and the R Functions Framework:
Now create new terminal. (âž• in the terminal) run the service:
Rscript create-app.R --target=hello
You’ll see the console output:
Starting server to listen on port 8080
Go to localhost:8080
to test your server.
Deploy to Cloud Run
Now let’s deploy our app to Cloud Run.
1. Download the Functions Framework binary
curl -O https://github.com/averikitsch/functions-framework-r/blob/master/examples/functionsframework_0.0.0.9000.tgz
2. Create a Dockerfile:
3. Build and Run:
Building the container takes a bit, but after it’s built, it runs well.
Test on Cloud Run
After deploying, you’ll get a URL like:
https://hellor-q7vieseilq-uc.a.run.app
Now feel free to create a more advanced R application!
Learn More
Thanks for reading!
If you enjoyed this article, you may be interested in the following resources: