DS4PS / cpp-523-spr-2021

http://ds4ps.org/cpp-523-spr-2021/
1 stars 3 forks source link

Simple question about "$" in the .rmd file for Lab-03 #9

Open mtwelker opened 3 years ago

mtwelker commented 3 years ago

I'm trying to understand the r code, and it looks like the dollar sign does multiple things. Under Question 2, there are dollar signs around the line: $test = b_0 + b_1 \cdot tqual + e1$ I can see that it changes the font and strips out the spaces. What do you call this, and what is the purpose? Would it mainly just be used to display mathematical expressions? Is it a markdown or r function?

jacobtnyoung commented 3 years ago

The dollar signs are used to create an equation. For example, $2 = 10 \div 5$ would write 2 = 10 divided by 5 in the html output.

lecy commented 3 years ago

There is an open-source publishing language called LaTeX. It includes a library for typesetting mathematical formulas.

Any time you see fancy math formulas in lecture notes and labs it is usually latex in the file.

When you add latex code to the RMD documents you identify the code for the compiler with dollar signs:

https://tex.stackexchange.com/questions/171711/how-to-include-latex-package-in-r-markdown

$$ y_{ij} = b_{ij} + \beta_{0} + \beta_{1} $$

When you knit your RMD document it is doing lots of things like converting markdown formatting to HTML tags, running R code and embedding output, importing images, and in this case running the latex formulas and embedding the resulting math objects in the rendered document.

So in short, RMD files are powerful because you can import lots of other tools to customize publication-quality reports and tutorials.

mtwelker commented 3 years ago

Thanks! @lecy , I read the link you included from stackexchange, and it seems to indicate that in order to use LaTeX in R Studio, you have to include the command \usepackage{bbm} or reference bbm in some way, which I don't find in our RMD file for Lab 03. Is there some other command you used to make it possible to use LaTeX in this case?

lecy commented 3 years ago

Sorry, that post was a little misleading. They were asking about loading a special fonts package for LaTeX, which included that extra command in the YAML header.

The genius behind R Markdown has been working hard to integrate a lot of features into the RMD environment. The R Studio team has actually created a distinct version of LaTeX for R users called TinyTex. This is installed with knitr, the package that knits RMD files.

https://bookdown.org/yihui/rmarkdown-cookbook/install-latex.html

You formerly had to install extra software on your computer to use all of the LaTeX features, but now they are bundled fairly seamlessly when you install knitr. You don't need to load special packages to use them.

Since you are new to the R experience, you might now appreciate how amazing it is to see all of these tools come together into a single environment. R Studio is the command center that runs dozens of different programs for you so that you can focus on writing code and translating results into meaningful text, tables, and graphics without switching between programs. It has tremendously simplified the workflow the efforts needed to document and maintain large projects.

It is analogous to being an early adopter of computers, when you literally needed to buy parts and build your own computer, then write your own operating system, in order for it to work. You can imagine how amazing it would have been to order an Apple machine that arrived fully assembled with a native operating system, a word processor, and spreadsheets. That is what it feels like to install R Studio for people that were using R when it was a niche language used by academics.