Skip to content

Commit 47aa656

Browse files
committed
Add initial example script in webR application
1 parent 34f1589 commit 47aa656

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/repl/components/Editor.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ export function FileTabs({
108108
);
109109
}
110110

111+
// An example R script analysing and plotting mtcars using base R
112+
const initialScript = `# Dataset overview and summary statistics
113+
head(mtcars)
114+
summary(mtcars)
115+
116+
# Visualization: fuel efficiency vs vehicle weight
117+
plot(mtcars$wt, mtcars$mpg,
118+
xlab = "Weight (1000 lbs)",
119+
ylab = "Miles per Gallon",
120+
main = "Fuel Efficiency vs Vehicle Weight",
121+
pch = 19)
122+
123+
# Fitted linear regression line
124+
trend <- lm(mpg ~ wt, data = mtcars)
125+
abline(trend, col = "red", lwd = 2)
126+
127+
# Calculate correlation
128+
cor(mtcars$mpg, mtcars$wt)
129+
130+
# Multiple linear regression model
131+
model <- lm(mpg ~ wt + hp + cyl, data = mtcars)
132+
summary(model)
133+
`;
134+
111135
export function Editor({
112136
webR,
113137
terminalInterface,
@@ -369,7 +393,7 @@ export function Editor({
369393
if (!editorRef.current) {
370394
return;
371395
}
372-
const state = EditorState.create({ extensions: scriptExtensions });
396+
const state = EditorState.create({ extensions: scriptExtensions, doc: initialScript });
373397
const view = new EditorView({
374398
state,
375399
parent: editorRef.current,

0 commit comments

Comments
 (0)