Skip to content

Commit

Permalink
simple notebook example
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Nov 20, 2023
1 parent 5afb721 commit c1a710a
Showing 1 changed file with 157 additions and 5 deletions.
162 changes: 157 additions & 5 deletions notebooks/xeus-r.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,181 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Simple code execution"
"# Builtin data structures\n",
"\n",
"Vectors, lists, data frames "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"# simple data structures\n",
"1:10\n",
"letters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"# lists\n",
"list(a = 42, b = 1:5, c = sample(LETTERS, 10))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"# data frames\n",
"head(mtcars)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"# tibbles\n",
"suppressPackageStartupMessages({\n",
" library(dplyr)\n",
"})\n",
"\n",
"mtcars %>%\n",
" group_by(cyl) %>%\n",
" summarise(mpg = mean(mpg))"
]
},
{
"cell_type": "markdown",
"metadata": {
"vscode": {
"languageId": "r"
}
},
"source": [
"At the moment, these automatically go through `display()` > `prepare_mimebundle()` > `repr()`, which offers several options in the mime bundle. I'm not sure this is the right approach, e.g. the automatic fancy display for simple data structures is somewhat overwhelming. I believe `display()` should be explicit. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"IRdisplay::prepare_mimebundle(1:10)\n",
"IRdisplay::prepare_mimebundle(list(a = 42, b = 1:5, c = sample(LETTERS, 10)))\n",
"IRdisplay::prepare_mimebundle(head(mtcars))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# plots"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"# base graphics\n",
"boxplot(count ~ spray, data = InsectSprays, col = \"lightgray\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"# ggplot2\n",
"options()\n",
"library(ggplot2)\n",
"\n",
"ggplot(mpg, aes(displ, hwy, colour = class)) + \n",
" geom_point()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# html widgets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"a = 3"
"suppressPackageStartupMessages({\n",
" library(htmltools)\n",
" library(plotly)\n",
"})\n",
"\n",
"tagList(\n",
" plot_ly(diamonds, x = ~carat, height = 200),\n",
" plot_ly(diamonds, x = ~price, height = 200)\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 4.3.1 (xr)",
"language": "text/x-R",
"display_name": "R 4.3.1 (xr)",
"language": "R",
"name": "xr"
},
"language_info": {
"codemirror_mode": "",
"file_extension": "R",
"mimetype": "text/x-R",
"name": "xr",
"name": "R",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "4.3.1"
}
},
Expand Down

0 comments on commit c1a710a

Please sign in to comment.