> ## Documentation Index
> Fetch the complete documentation index at: https://help.milton.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Write and run R or Python scripts

Projects can hold your analysis code next to your manuscript. Code files are edited in Milton, co-written live with your co-authors, and read by the agent.

## Code files you can edit

`.R`, `.py`, `.jl`, `.m`, `.sh`, `.sql`, `.sas`, `.js`, `.ts`, `.json`, `.yaml`, `.yml` and `.toml`.

To create one, in the project's **Writing** tab click **New file** and choose `.R` or `.py`, or upload your files.

> [!NOTE]
>
> Code files uploaded before Milton 1.6 stay as plain files. Upload them again to edit them in Milton.

## Before you run a script

R or Python must be installed on your device. Milton finds them by itself. To choose a specific one, go to **Settings** → **Preferences** → **R and Python** and click **Choose…**. A missing one shows "Not found".

![Settings, Preferences, R and Python, with the versions Milton found and Choose…](https://mintcdn.com/milton-help/CQbZfUaauwZBJQyI/images/code-interpreters-settings.png?fit=max\&auto=format\&n=CQbZfUaauwZBJQyI\&q=85\&s=14eec9be4c83f3e48ba851f4f5756ee9)

## Run a script

1. Open a `.R` or `.py` file.
2. Click **Run**. It becomes **Stop** while the script runs.
3. The **Output** tab shows what the script prints, whether it finished ("Done · 1.2 s", "Failed (exit code 1)"…), and the files it produced.

![A Python script open with the Run button and the Output tab showing the console and produced files](https://mintcdn.com/milton-help/kiy3RmS7wYTX7rS6/images/script-run-output.png?fit=max\&auto=format\&n=kiy3RmS7wYTX7rS6\&q=85\&s=a05b05fe027d2f5d2b9e2490ba3dc52f)

Files the script writes come back into the project, at the same place. Nothing is deleted. There's no time limit.

![An R script after Run: Done in the Output tab and the file it produced in the file tree](https://mintcdn.com/milton-help/CQbZfUaauwZBJQyI/images/code-r-script-output.png?fit=max\&auto=format\&n=CQbZfUaauwZBJQyI\&q=85\&s=15df9b021b3f4f4f9cefa0992fd394be)

The console output stays on your device until the next run. It isn't saved or shared.

## Safety

Scripts run on your device. If a co-author or the agent changed the code since you last ran it, Milton asks first, in a **Run code?** window: "*Name* changed code in this project (*files*). Run it on this device?" Click **Run** or **Cancel**.

## Good to know

* Running scripts is free.
* In a shared project, adding the files a script produces (images, data) needs a subscription, and viewers can't add them. Otherwise they show "Kept on this device".
* If R or Python is missing, Milton says so, for example "Python is not installed on this device. Install it from python.org, then press Run again.", with a link to **Settings**.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.