Show only results in rmarkdown without code - r-markdown

I know one solution is {r var, echo=FALSE} but that requires that I name every result in the chunk. Is there an easier way?

Actually I found that {r echo=FALSE} works.

Related

plots in r markdown don't appear if they are the same

I was trying to generate an r markdown html/pdf docuement and everything worked apart from the code and images didn't appear. What I discovered is that images don't appear if you have two that are the same. In the example below you only get 2 plots, event though 4 are asked for. If you give them all different titles (main='xx') then they all appear.
Is this a known issue that could be causing my problems? Any advice appreciated.
```{r pressure, echo=TRUE}
cat('HELLO')
plot(pressure) # only one of these plots bu it seems to be random
cat('HELLO1')
plot(pressure) #
cat('HELLO2')
plot(pressure) #
cat('HELLO3')
plot(pressure)
plot(pressure,main='plot3') #this one plots

Print equation of linear regression model using RMarkdown

I currently have some rather long inline code for producing an equation of just a simple linear regression:
lm(var1 ~ var2 + var3)
But I could have sworn at some point recently I saw some very succinct inline code to produce an equation of that model, but I seem to not have saved it. Any ideas?
(sorry, I found it, using the equatiomatic package)
You don’t need need a package for inline equations. Just put you equation in Rmarkdown between 2 $, example below
$lm(var1 ~ var2 + var3)$
which looks like this rendered in Rmarkdown

Include begin{document}, end{document} in LaTeX tables code generated in Stata

While using estpost/esttab/esttab in Stata to generate LaTeX tables, latex initialization syntax such as documentclass{}, begin{document}, and end{document} are never included. This means that every LaTeX code generated needs for these to be added.
I have many many tables to create. Is it possible to include these through Stata itself?
There are two potential solutions, the first is to include these using the prehead and postfoot options, which allow you to do this directly, but make table formatting a bit more difficult. Or there is the option to simply use include{asdf.tex} in another file.
Solution 1 example:
sysuse auto, clear
reg price mpg
esttab using "temp.tex", ///
prehead("\documentclass{article}\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\begin{document}\begin{tabular}{l*{1}{c}}") ///
postfoot("\end{tabular}\end{document}") ///
replace
This will make a basic table, but doing things like including a title become more difficult with this option.
Second solution, in a tex file, you can include any number of tables thusly:
\documentclass{article}
\begin{document}
\input{any_tex_file.tex}
\input{any_tex_file2.tex}
\end{document}
and in this way you can include all of your tables.
Hope this helps
A better solution could be including this command into your stata esttab output commands
booktabs page(column)

Default code folding by individual chunk in rmarkdown

I am writing up a lesson in HTML using rmarkdown to demonstrate how to implement analytic methods in R, and because of this the document has a lot of code that is needed to understand those methods, but also a lot of code that is used only for generating plots and figures. I would like to show the first sort of code by default, and leave the plotting code available for students to view but hidden by default.
I know that rmarkdown has recently added support for code folding by setting the code_folding html_document argument to either show or hide. However, this either leaves all code chunks unfolded or folded by default -- is there any way to indicate whether individual code chunks should be shown or folded by default while allowing code folding?
Thank you!
I arrived here wondering the same thing. This is a not a perfect solution, but I write the code twice: once in regular markdown (so it displays - note no {r} after the three backticks), and another time in a code chunk (so it runs).
Example:
This runs but doesn't display the actual code
```{r}
5 * 5
```
This results in both the code and execution being displayed
```
5 * 5
```
```{r}
5 * 5
```
Which results in:
David Fong provided a perfect solution for this in their answer: https://stackoverflow.com/a/56657730/9727624
To override the state, use {r class.source = "fold-hide"} if the yaml setting is show, and {r class.source = "fold-show"} if the setting is hide.

Pie charts in Stata

I'm using the code below to draw some graphs and combine them. When I execute the entire file I get the error:
"Invalid Syntax r(198)".
And the code stops at the code segment below. However, when I run the code segment separately the program works without a flaw. Can you please help me understand what's causing this issue?
*pie chart
foreach i in "SPA" "EPD"{
graph pie billed_amount if type== "`i'", over(service_id) saving(gg`i',replace)
local gg `gg' "gg`i'"
}
local gg: subinstr local gg "ggSPA" `""ggSPA""'
gr combine `gg'
graph export "C\provider.png", as(png) replace
graph drop _all
Without any context -- whether the code before this that makes a difference -- or a dataset to use -- how can we tell? The problem lacks a minimal complete verifiable example. See https://stackoverflow.com/help/mcve for this and future questions.
That said, this seems to be a very roundabout way to get two pie charts side-by-side. That doesn't require a loop and it doesn't require graph combine.
graph pie billed_amount if inlist(type, "SPA", "EPD"), over(service_id) by(type)
graph export "C\provider.png", as(png) replace
Whether you want to drop all graphs afterwards is quite immaterial to the problem posed.