The Code Ocean filesystem
The key file paths to know are /code
, /data
, and /results
. These correspond to the three panes in the workspace:
code
data
results
When possible, use relative paths – for example ../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, add ..
where necessary, for example load('../../data/my_data.csv')
. This will go up two parent directories and 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 - 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
See this Linux Manual page for more information.