Skip to content

Commit a4ee1b3

Browse files
committed
fix #79; R (Rscript) data loaders
1 parent 6c2ec69 commit a4ee1b3

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

docs/data-loaders.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
**Data loaders** are special cells that run "ahead" at build time via an interpreter, rather than "live" when you view a notebook in the browser. Data loaders are useful for preparing static data, ensuring consistency and stability, and improving performance. Think of data loaders as a generalization of [database connectors](./databases) that allow languages besides SQL.
1111
</script>
1212
<script id="7" type="text/markdown">
13-
Notebooks currently support Node.js and Python data loaders. We will likely add additional interpreters in the future.
13+
Notebooks currently support Node.js, Python, and R data loaders. We will likely add additional interpreters in the future.
1414
</script>
1515
<script id="3" type="text/markdown">
1616
As an example, here is a trivial Python cell that says hello, and reports the current version of Python:
@@ -144,4 +144,15 @@
144144
<script id="30" type="text/markdown">
145145
If you have a virtual environment (`.venv`) in the same directory as the notebook, it will automatically be used. However, packages are not installed implicitly; you must install packages yourself, typically using `pip`. (And we recommend using `pip freeze` to create a `requirements.txt`.)
146146
</script>
147+
<script id="31" type="text/markdown">
148+
## R data loaders
149+
150+
R data loaders require R to be installed in one of the following locations:
151+
152+
- `/opt/homebrew/bin/Rscript` (Homebrew)
153+
- `/opt/local/bin/Rscript` (MacPorts)
154+
- `/Library/Frameworks/R.framework/Resources/bin/Rscript` (official R installer)
155+
- `/usr/local/bin/Rscript` (official R installer)
156+
- `/usr/bin/Rscript` (operating system)
157+
</script>
147158
</notebook>

docs/observable.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
</a>
116116
<a href="/notebook-kit/data-loaders" style="color: inherit;">
117117
<div>Data loaders</div>
118-
<div style="opacity: 0.8; font-weight: normal; font-size: 14px;">Prepare static data by running Node.js and Python cells</div>
118+
<div style="opacity: 0.8; font-weight: normal; font-size: 14px;">Prepare static data by running Node.js, Python, or R</div>
119119
</a>
120120
<a href="/notebook-kit/desktop" style="color: inherit;">
121121
<div>Desktop</div>

src/interpreters/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export function getInterpreterCommand(interpreter: string): [command: string, ar
2020
return ["node", ["--input-type=module-typescript", "--permission", "--allow-fs-read=."]];
2121
case "python":
2222
return ["python3", []];
23+
case "r":
24+
return ["Rscript", ["-"]];
2325
default:
2426
throw new Error(`unknown interpreter: ${interpreter}`);
2527
}

src/lib/interpreters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {Cell} from "./notebook.js";
22

33
export function isInterpreter(mode: Cell["mode"]): boolean {
4-
return mode === "node" || mode === "python";
4+
return mode === "node" || mode === "python" || mode === "r";
55
}
66

77
export function getInterpreterExtension(format: Cell["format"]): string {

src/lib/notebook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface CellSpec {
3939
/** the committed cell value; defaults to empty */
4040
value?: string;
4141
/** the mode; affects how the value is evaluated; defaults to js */
42-
mode?: "js" | "ts" | "ojs" | "md" | "html" | "tex" | "dot" | "sql" | "node" | "python";
42+
mode?: "js" | "ts" | "ojs" | "md" | "html" | "tex" | "dot" | "sql" | "node" | "python" | "r";
4343
/** if true, the editor will stay open when not focused; defaults to false */
4444
pinned?: boolean;
4545
/** if true, implicit display will be suppressed; defaults to false */

src/lib/serialize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ function serializeMode(mode: Cell["mode"]): string {
7171
return "application/vnd.node.javascript";
7272
case "python":
7373
return "text/x-python";
74+
case "r":
75+
return "text/x-r";
7476
case "ojs":
7577
return "application/vnd.observable.javascript";
7678
case "ts":
@@ -96,6 +98,8 @@ function deserializeMode(mode: string | null): Cell["mode"] {
9698
return "node";
9799
case "text/x-python":
98100
return "python";
101+
case "text/x-r":
102+
return "r";
99103
case "application/vnd.observable.javascript":
100104
return "ojs";
101105
case "text/x-typescript":

0 commit comments

Comments
 (0)