The Code Ocean filesystem

The key file paths to familiarize yourself with are /code , /data , and /results. These correspond to the three panes in your workspace: Code, Data, and Results.

When possible, use relative paths – ../data  and ../results – which will make it easier for users who download your code to run things on their own computer. (See Wikipedia for more information on relative paths.)

When you run your code, the initial working directory will be /code. If you use relative paths, you will rarely need to refer to it. If you have code in a subfolder, don't forget to add .. as necessary, e.g. load('../../data/my_data.csv'). This would go up two parent directories and then look for ./data/my_data.csv.

Symbolic Links

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 (typically 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 at /code/input_images, directing your code to the data you've uploaded to the Data pane.

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


See this Linux Manual page for more information.

Did this answer your question?