The Code Ocean filesystem

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

When possible, use relative paths – e.g. ../data  and ../results – to  make it easier for users who download your code to run things locally.

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.

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  on Code Ocean):

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. So if your input images were in a folder called input_images  on your computer, and now they are in /data, your code will find them in their new location.

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

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?