Running a Simple R Script on Bacalhau
You can use official Docker containers for each language, like R or Python. In this example, we will use the official R container and run it on Bacalhau.
In this tutorial example, we will run a "hello world" R script on Bacalhau.
Prerequisites
To get started, you need to install the Bacalhau client, see more information here
1. Running an R Script Locally
To install R follow these instructions A Installing R and RStudio | Hands-On Programming with R. After R and RStudio are installed, create and run a script called hello.R
:
Run the script:
Next, upload the script to your public storage (in our case, IPFS). We've already uploaded the script to IPFS and the CID is: QmVHSWhAL7fNkRiHfoEJGeMYjaYZUsKHvix7L54SptR8ie
. You can look at this by browsing to one of the HTTP IPFS proxies like ipfs.io or w3s.link.
2. Running a Job on Bacalhau
Now it's time to run the script on Bacalhau:
Structure of the command
bacalhau docker run
: call to Bacalhaui ipfs://QmQRVx3gXVLaRXywgwo8GCTQ63fHqWV88FiwEqCidmUGhk:/hello.R
: Mounting the uploaded dataset at/inputs
in the execution. It takes two arguments, the first is the IPFS CID (QmQRVx3gXVLaRXywgwo8GCTQ63fHqWV88FiwEqCidmUGhk
) and the second is file path within IPFS (/hello.R
)r-base
: docker official image we are usingRscript hello.R
: execute the R script
When a job is submitted, Bacalhau prints out the related job_id
. We store that in an environment variable so that we can reuse it later on:
Declarative job description
The same job can be presented in the declarative format. In this case, the description will look like this:
The job description should be saved in .yaml
format, e.g. rhello.yaml
, and then run with the command:
3. Checking the State of your Jobs
Job status: You can check the status of the job using bacalhau list
.
When it says Published
or Completed
, that means the job is done, and we can get the results.
Job information: You can find out more information about your job by using bacalhau describe
.
Job download: You can download your job results directly by using bacalhau get
. Alternatively, you can choose to create a directory to store your results. In the command below, we created a directory (results
) and downloaded our job output to be stored in that directory.
4. Viewing your Job Output
To view the file, run the following command:
Futureproofing your R Scripts
You can generate the job request using bacalhau describe
with the --spec
flag. This will allow you to re-run that job in the future:
Support
If you have questions or need support or guidance, please reach out to the Bacalhau team via Slack (#general channel).