Sometimes you might be faced with the fact that your exec.R file isn’t working properly. This may be due to problems in the file itself, in the way your script tries to upload the results to a bucket or on how the pods are handling arguments.

This vignette tries to show you how to debug your deployment on these three scenarios while at the same time giving you an example of how to write your exec.R.

## Something’s fishy

library(kuber)

kub_create_cluster("my-cluster")
#> ✔  Creating cluster

#> ✔  Fetching cluster information
#> ✔  Fetching bucket information
#> ✔  Creating bucket
#> ●  Edit ~/my-dir/exec.R'
#> ●  Create ~/my-dir/list.rds with usable objects
#> ●  Run kub_push_task("~/my-dir")

file.edit("~/my-dir/exec.R")
file.copy("~/my-list.rds", "~/my-dir/list.rds", TRUE)

#> ✔  Building image
#> ✔  Authenticating
#> ✔  Pushing image
#> ✔  Removing old jobs
#> ✔  Creating new jobs

#> ✔  Authenticating
#> ✔  Setting cluster context
#> ✔  Creating jobs
#> ●  Run kub_list_pods() to follow up on the pods

But now, when you run kub_list_pods(), the STATUS column says “Error” or some other equivalent undesirable message. First you must check whether

The first debug strategy should be lightly editing your exec.R file in order for it to run in your local machine. For instance, replace every instance of save_rds() with saveRDS() and run the script locally:

$cd ~/my-dir/$ Rscript --vanilla exec.R 1 my-bucket

If the expected RDS files aren’t written to disk, then your problem might be in the code. You can also run the script step by step by also replacing the command line arguments at the top of the file:

idx <- 1   # as.numeric(args[1])

In case none of this works, then consider whether

Now you should see what’s happening to the pods themselves. Run kub_list_pods() and copy the name of the pod you want to examine:

$kubectl logs [POD_NAME] This command will show you the output of your script, which could inform your debugging process. If this isn’t enough, try running the docker container manually: $ docker run my-image Rscript exec.R 1 my-bucket

This will execute your exec.R inside the container environment and is the closest you will get to your pod without getting inside it. Speaking of which, if nothing has worked up until now, then you should see whether

To do this, you must open two terminal windows. In the first one, run your container:

$docker run my-image In the second one, get your container’s ID in order to access it: $ docker container list
\$ docker exec -it [CONTAINER_ID] /bin/bash

With this last command, you’ll essentially be ssh-ing into your pod. This allows you to run any shell command you want, run R scripts in the local environment or even edit any files that might not be setup properly.