Using capsule paths in my code

The key file paths to know are /code , /data , /results , and /scratch. These correspond to the panes in the workspace:

  • code

  • data

  • results

  • scratch

Use relative paths where possible – for example, ../data and ../results – this simplifies the process for those who download the code to run things locally.

The initial working directory will be /code when your code is run. You will hardly need to refer to it if you use relative paths.

If you have code in a subfolder, add .. where necessary, for example

load('../../data/my_data.csv'). This will go up two parent directories and look for ./data/my_data.csv.

Use symbolic links to alias paths. This is useful if you have numerous hardcoded paths that would be time-consuming to change manually. Consider the following shell script - called run.sh on Code Ocean:

// #!/bin/bash
ln -s ../data ./input_images
python -u demo

The ln -s command creates a link that points to /data where the code might otherwise look for files in /code/input_images. If your input images were in a folder called input_images and they are now in /data, the code will find them in the new location.

Note: if the path your code is expecting includes non-existing folders, you'll need to create them first using mkdir -p

#!/bin/bash
mkdir -p /results/analysis_one/fig1
ln -s /results/analysis_one/fig1 /code/fig1
Rscript fig1.R

Last updated