Skip to content

Instantly share code, notes, and snippets.

@kbroman
Created June 11, 2019 13:17
Show Gist options
  • Save kbroman/2b781ab4ec24437cb2ac03d1eb01f8dc to your computer and use it in GitHub Desktop.
Save kbroman/2b781ab4ec24437cb2ac03d1eb01f8dc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"this has class a"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"x <- 1:5\n",
"class(x) <- \"a\"\n",
"print.a <- function(x, ...) cat(\"this has class a\\n\")\n",
"x"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<ol class=list-inline>\n",
"\t<li>1</li>\n",
"\t<li>2</li>\n",
"\t<li>3</li>\n",
"\t<li>4</li>\n",
"\t<li>5</li>\n",
"</ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 1\n",
"\\item 2\n",
"\\item 3\n",
"\\item 4\n",
"\\item 5\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 1\n",
"2. 2\n",
"3. 3\n",
"4. 4\n",
"5. 5\n",
"\n",
"\n"
],
"text/plain": [
"this has class a"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"class(x) <- c(\"a\", \"numeric\")\n",
"x"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"this has class a"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"class(x) <- c(\"a\", \"b\")\n",
"x"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment