\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Niki (worlddoit)} \pdfinfo{ /Title (r-part4-1.pdf) /Creator (Cheatography) /Author (Niki (worlddoit)) /Subject (r part4.1 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{566BA3} \definecolor{LightBackground}{HTML}{F4F5F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{r part4.1 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Niki (worlddoit)} via \textcolor{DarkBackground}{\uline{cheatography.com/170195/cs/35878/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Niki (worlddoit) \\ \uline{cheatography.com/worlddoit} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 4th December, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Dataframe 1}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{data.frame(data, row.names = NULL,...) \{\{noshy\}\} \newline data.frame(name1 = vector1, name2 = vector2,...) \{\{noshy\}\} \newline \textgreater{} vec1\textless{}-c( 25, 24, 21, 23, 22) \{\{noshy\}\} \newline \textgreater{} vec2\textless{}-c("M","F","F","M","F") \{\{noshy\}\} \newline \textgreater{} vec3\textless{}-c("A1","A2","A3","A1","A2") \{\{noshy\}\} \newline \textgreater{} (df1 \textless{}- data.frame(age=vec1, sex=vec2, group=vec3))\{\{noshy\}\} \newline age sex group \{\{noshy\}\} \newline 1 25 M A1 \newline 2 24 F A2 \newline 3 21 F A3 \newline 4 23 M A1 \newline 5 22 F A2} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(**Basics)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.83229 cm} x{1.14471 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Dataframe 2}} \tn % Row 0 \SetRowColor{LightBackground} `is.object(df1)`\{\{noshy\}\} & TRUE \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `typeof(df1)`\{\{noshy\}\} & "list" \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `class(df1)`\{\{noshy\}\} & \seqsplit{"data.frame"} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} `sloop::otype(df1)`\{\{noshy\}\} & "S3" \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} `df1{[}c(1,2){]} \{\{nl\}\} df1{[}{[}2{]}{]} \{\{nl\}\} df1{[}{[}"sex"{]}{]} \{\{nl\}\} df1\$sex`\{\{noshy\}\} & \seqsplit{Subsetting} \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{(**Basics)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{1}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Dataframe 3}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Important functionality: \newline % Row Count 1 (+ 1) `str(df1)` \newline % Row Count 2 (+ 1) `attributes(df1)` \{\{noshy\}\} \newline % Row Count 3 (+ 1) `merge()` \newline % Row Count 4 (+ 1) merge by common columns or row names \newline % Row Count 5 (+ 1) `cbind()` `rbind()` \newline % Row Count 6 (+ 1) `head()` \newline % Row Count 7 (+ 1) visualize the first rows of a df \newline % Row Count 8 (+ 1) `attach()` \newline % Row Count 9 (+ 1) df can be attached \newline % Row Count 10 (+ 1) `summary()` \newline % Row Count 11 (+ 1) basic statistics% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(**Basics)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Dataframe 4}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Dataframes can contain lists: \newline % Row Count 1 (+ 1) `1) df \textless{}- data.frame(x=1:3); df\$y \textless{}- list(1:2,1:3,1:4) ` \{\{noshy\}\} \newline % Row Count 3 (+ 2) `2) df \textless{}- data.frame(x = 1:3, y = I(list(1:2, 1:3, 1:4))) ` \{\{noshy\}\} \newline % Row Count 5 (+ 2) Can be also matrices: \newline % Row Count 6 (+ 1) `dfm \textless{}- data.frame(x = 1:3 * 10)` \{\{noshy\}\} \newline % Row Count 7 (+ 1) `dfm\$y \textless{}- matrix(1:9, nrow = 3)` \{\{noshy\}\} \newline % Row Count 8 (+ 1) `dfm\$z \textless{}- data.frame(a = 3:1, b = letters{[}1:3{]})` \{\{noshy\}\}% Row Count 10 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(***Adanced)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{2}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Tibbles 1}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Part of the `tidyverse` \newline % Row Count 1 (+ 1) More flexible than datasets: \newline % Row Count 2 (+ 1) `(tib0\textless{}-tibble(x = 1:3, y = 1, z = x\textasciicircum{}2+y,` \{\{noshy\}\} \newline % Row Count 4 (+ 2) `name = letters{[}1:3{]}, lis = list(1:5,1:10,1:20)))` \{\{noshy\}\} \newline % Row Count 6 (+ 2) Can be more rigid: recycling \newline % Row Count 7 (+ 1) `(tib2 \textless{}- tibble::tibble(age=1, sex=vec2, group=vec3))` \{\{noshy\}\}% Row Count 9 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(**Basics)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Tibbles 2}} \tn % Row 0 \SetRowColor{LightBackground} `attributes(tib0)`\{\{noshy\}\} & \$names, \{\{nl\}\}\$row.names, \{\{nl\}\}\$class \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `mode(tib0)`\{\{noshy\}\} & "list" \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `typeof(tib0)`\{\{noshy\}\} & "list" \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `class(tib0)`\{\{noshy\}\} & "tbl\_df" \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} `sloop::otype(tib0)`\{\{noshy\}\} & "S3" \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} `is\_tibble()`\{\{noshy\}\} & Test if tibble \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} `as.data.frame()`\{\{noshy\}\} & Convert to df \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} `tribble()`\{\{noshy\}\} & Table format \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{(**Basics)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{1}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Control flow}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`if()` statements \newline % Row Count 1 (+ 1) `\textgreater{} if(x \textgreater{} 10) \{y\textless{}-x ; print(y)\}` \{\{noshy\}\} \newline % Row Count 2 (+ 1) `+ else \{y\textless{}-x+1 ; print(y)\}` \{\{noshy\}\} \newline % Row Count 3 (+ 1) `switch()` tests an expression against elements of a list. \newline % Row Count 5 (+ 2) `switch(x, "red", "green", "blue", stop("No"))` \{\{noshy\}\} \newline % Row Count 7 (+ 2) `case\_when()` statements \newline % Row Count 8 (+ 1) `\textgreater{} dplyr::case\_when(` \{\{noshy\}\} \newline % Row Count 9 (+ 1) `+ x\%\%5==0\textasciitilde{}"a",` \{\{noshy\}\} \newline % Row Count 10 (+ 1) `+ x\textgreater{}6\textasciitilde{}"great",` \{\{noshy\}\} \newline % Row Count 11 (+ 1) `+ TRUE \textasciitilde{} as.character(x))` \{\{noshy\}\} \newline % Row Count 12 (+ 1) `for` loops \newline % Row Count 13 (+ 1) `\textgreater{} for (i in 1:4) print(i)` \{\{noshy\}\} \newline % Row Count 14 (+ 1) `next` exits an iteration \newline % Row Count 15 (+ 1) `break` exits the loop \newline % Row Count 16 (+ 1) `while()` statement \newline % Row Count 17 (+ 1) `\textgreater{} while(x \textless{} 4) \{print(x); x\textless{}-x+1\}` \{\{noshy\}\} \newline % Row Count 18 (+ 1) `repeat\{\}` statement \newline % Row Count 19 (+ 1) `repeat \{print(x); x\textless{}-x+1; if(x==5) break\}` \{\{noshy\}\}% Row Count 21 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(**Basics)(***Advanced)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Functions 1}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{ "Everything that exists is an object. Everything that happens is a function call." }} \newline % Row Count 2 (+ 2) Types of functions: \newline % Row Count 3 (+ 1) {\bf{closure functions}}, these are the usual functions create or encounter while using R. \newline % Row Count 5 (+ 2) {\bf{builtin functions}}, primitive/internal functions that generally rely on C code and pass their arguments in an evaluated way. \newline % Row Count 8 (+ 3) {\bf{special functions}}, primitive/internal functions that rely on C code and pass their arguments in an unevaluated way \newline % Row Count 11 (+ 3) The typical syntax for a closure function \newline % Row Count 12 (+ 1) `fname \textless{}- function(arg1, arg2, ... )\{` \{\{noshy\}\} \newline % Row Count 13 (+ 1) ` body: expressions and return value \}` \{\{noshy\}\} \newline % Row Count 15 (+ 2) `fname(arg1 = val1, arg2 = val2)` \{\{noshy\}\} \newline % Row Count 16 (+ 1) Example: \newline % Row Count 17 (+ 1) `\textgreater{} mysum \textless{}- function(x,y)\{x+y \#just make a sum +\}` \{\{noshy\}\} \newline % Row Count 19 (+ 2) `\textgreater{} mysum(1,2)` \{\{noshy\}\} \newline % Row Count 20 (+ 1) `{[}1{]} 3` \{\{noshy\}\}% Row Count 21 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(**Basics)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions 2}} \tn % Row 0 \SetRowColor{LightBackground} `is.object(mysum)` \{\{noshy\}\} & FALSE \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `typeof(mysum)`\{\{noshy\}\} & "closure" \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `class(mysum)`\{\{noshy\}\} & "function" \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `sloop::otype(mysum)`\{\{noshy\}\} & "base" \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} `mysum`\{\{noshy\}\} & `function(x,y)\{x+y\}` \{\{nl\}\} prints \{\{noshy\}\} \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} `typeof(sum)`\{\{noshy\}\} & "builtin" functions \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} `mean(2,3,10) !=\{\{nl\}\} mean(c(2,3,10))`\{\{noshy\}\} & 2 != \{\{nl\}\} 5 \tn % Row Count 16 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{(**Basics)(***Advanced)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.63781 cm} x{2.33919 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions 2}} \tn % Row 0 \SetRowColor{LightBackground} `is.object(mysum)` & FALSE \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `typeof(mysum)` & "closure" \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `class(mysum)` & "function" \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{`sloop::otype(mysum)`} & "base" \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} `mysum` & `function(x,y)\{x+y\}` \{\{nl\}\} prints \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} typeof(sum) & "builtin" functions \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} `mean(2,3,10) !=\{\{nl\}\} mean(c(2,3,10))` & 2 != \{\{nl\}\} 5 \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{(**Basics)(***Advanced)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Functions 3}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Make lists of functions: \newline % Row Count 1 (+ 1) `\textgreater{} funs \textless{}- list(` \{\{noshy\}\} \newline % Row Count 2 (+ 1) `+ half = function(x) x / 2,` \{\{noshy\}\} \newline % Row Count 3 (+ 1) `+ double = function(x) x * 2 +)` \{\{noshy\}\} \newline % Row Count 4 (+ 1) `\textgreater{} funs\$double(10); funs\$half(10)` \{\{noshy\}\} \newline % Row Count 5 (+ 1) Arguments are evaluated only if accessed \newline % Row Count 6 (+ 1) `\textgreater{} f\textless{}- function(x,y) x+1 \#y is ignored ` \{\{noshy\}\} \newline % Row Count 8 (+ 2) `\textgreater{} f(2)` \{\{noshy\}\} \newline % Row Count 9 (+ 1) `{[}1{]} 3` \{\{noshy\}\} \newline % Row Count 10 (+ 1) Arguments can be defined later \newline % Row Count 11 (+ 1) `\textgreater{} f\textless{}- function(x,y) \{y\textless{}-2;x+y\} ` \{\{noshy\}\} \newline % Row Count 12 (+ 1) `\textgreater{} f(2)` \{\{noshy\}\} \newline % Row Count 13 (+ 1) `{[}1{]} 4` \{\{noshy\}\} \newline % Row Count 14 (+ 1) Arguments can be forced \newline % Row Count 15 (+ 1) `\textgreater{} f \textless{}- function(x) \{` \{\{noshy\}\} \newline % Row Count 16 (+ 1) `+ force(x)` \{\{noshy\}\} \newline % Row Count 17 (+ 1) `+ 10` \{\{noshy\}\} \newline % Row Count 18 (+ 1) `+\}` \{\{noshy\}\} \newline % Row Count 19 (+ 1) `\textgreater{} f(stop("This is an error!"))` \{\{noshy\}\} \newline % Row Count 20 (+ 1) `Error in force(x) : This is an error!` \{\{noshy\}\} \newline % Row Count 21 (+ 1) A promise is forced when its value is needed \newline % Row Count 22 (+ 1) `\textgreater{} f\textless{}-function(x, label = deparse(x)) \{` \{\{noshy\}\} \newline % Row Count 24 (+ 2) `+ label \#this forces the promise` \{\{noshy\}\} \newline % Row Count 25 (+ 1) `+ x \textless{}- x + 1 \# change in x does not affect promise` \{\{noshy\}\} \newline % Row Count 27 (+ 2) `+ print(label)\}` \{\{noshy\}\} \newline % Row Count 28 (+ 1) `\textgreater{} f1\textless{}-function(x, label = deparse(x)) \{` \{\{noshy\}\} \newline % Row Count 30 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Functions 3 (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`+ x \textless{}- x + 1 \#the change in x will affect the label promise` \{\{noshy\}\} \newline % Row Count 2 (+ 2) ` + print(label)\}` \{\{noshy\}\} \newline % Row Count 3 (+ 1) `\textgreater{} f(1)` \{\{noshy\}\} \newline % Row Count 4 (+ 1) `{[}1{]} "1"` \{\{noshy\}\} \newline % Row Count 5 (+ 1) `\textgreater{} f1(1)` \{\{noshy\}\} \newline % Row Count 6 (+ 1) `{[}1{]} "2"` \{\{noshy\}\}% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(***Advanced)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}