Default code folding by individual chunk in rmarkdown - r-markdown

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.

Related

nomenclature in elsevier latex template

I got some trouble with nomenclature in Elsevier template. I followed this instruction proposed by delrocco.
and now when I wrote the \nomenclature command I got nothing (the box is empty)(please see the attached file). I do not know I must use tabular environment in the middle of the table* environment or use \nomenclature command. When I use tabular environment, I have columns that with different size (the fourth column go out of the box)(the proposed instruction needs making some change in template). I do not know it is the best solution or not. Also when I use the other solution with \mbox commant i received the error relates to the not proper for two column. I m confused.
I really appreciate any help
%\documentclass[review]{elsarticle}
\documentclass[3p,twocolumn]{elsarticle}
\usepackage{framed} % Framing content%###
\usepackage{multicol} % Multiple columns environment
\usepackage{nomencl} % Nomenclature package
\makenomenclature
\setlength{\nomitemsep}{-\parskip} % Baseline skip between items%###
\renewcommand*\nompreamble{\begin{multicols}{2}}
\renewcommand*\nompostamble{\end{multicols}}
\modulolinenumbers[5]
\usepackage{nomencl}
\makenomenclature
\journal{Journal of \LaTeX\ Templates}
\bibliographystyle{elsarticle-num}
\DeclareUnicodeCharacter{2212}{-}
\begin{document}
\begin{frontmatter}
\begin{abstract}
\end{abstract}
\begin{keyword}
%\texttt{elsarticle.cls}\sep \LaTeX\sep Elsevier \sep template
%\MSC[2010] 00-01\sep 99-00
\texttt{MMMMr}
%\MSC[2010] 00-01\sep 99-00
\end{keyword}
\end{frontmatter}
\begin{table*}[!t] %### for nomenculture
\begin{framed}
\nomenclature{$abbreviation$}{explanation for the abbreviation}
\nomenclature{\(c\)}{Speed of light in a vacuum}
\nomenclature{\(h\)}{Planck constant}
\printnomenclature
\end{framed}
\end{table*}
\end{document}

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

AWS Quicksight calculated fields gives incorrect result for simple division

I have a dataset with fields targeted and opens and I need to add calculated field opens per targeted which essentially means doing simple devision of those 2 values.
My calculated field is as follows
{opens}/{targeted}
but then displaying simple table with values they are completely incorrect
If I try any other operator like + * etc calculations are correct.
I'm completely out of ideas on how to debug this. I've simplified the dataset to just columns of targeted and opens, can't get any simpler.
Had the same problem, I fixed it by wrapping the columns with the sum() function. Like this:
sum({opens})/sum({targeted})
I think you need to make AWS understand that you are working with float numbers.
1.0*{opens}/{targeted}
if still not working try also
(1.0*{opens})/({targeted}*1.0)
it should give you the desired output (not tested, let me know if it doesnt work)

using a list of regressors and storing the values of betas

I have a list of circumstances and effects:
I want to generate a matrix with betas containing the values of betas. I am going to run the loop 10 times, because i am in fact going to bootstrap my observations.
So far I have tried:
local circumstances height weight
local effort training diet
foreach i in 1 10 {
reg outcome `circumstances' `effects'
* store in column i the values of betas of circumstances
* store in column i the values of betas of effort
}
Does anyone know what should the code look like in order to store those values?
Thank you
The pseudocode would first store in "column 1" the first lot of betas and then overwrite them (column 1) with the second lot of betas. Then it would do the same again for column 10 with the first lot of betas and the second lot of betas. That is a long way from anything that makes sense. Nothing in your pseudocode takes bootstrap samples from the dataset, although perhaps you are intending to add code for that later.
Stata doesn't really work with any idea of column numbers, although the idea makes sense to Mata.
Unless there are very specific reasons -- which you would need to spell out -- there is no need to write your own code ab initio for bootstrapping, as the whole point of bootstrap is to do that for you.
Here is complete code for a reproducible example of bootstrapping a silly regression:
sysuse auto, clear
bootstrap b_weight=_b[weight] b_price=_b[price] , reps(1000) seed(2803) : regress mpg weight price
See also the help for bootstrap to learn about its other options, including saving().
10 repetitions would be regarded as absurdly small for the number of bootstrap samples.

Why does dlib's neural net xml export contain different parameters for layers than specified by the trainer?

In DLib it is possible to simply output a neural net type via the dlib::net_to_xml(some_net, some_filename) function. It works fine, but it also displays information like for example the net type, learning_rate_multi. In my case for example it exports the following line for one of the layers (the rest of the exported xml is omitted for clarity):
<fc num_outputs='42' learning_rate_mult='1' weight_decay_mult='1' bias_learning_rate_mult='500' bias_weight_decay_mult='0'>
Those values are correct, except for learning_rate_mult and weight_decay_mult, which always show 1. I tried setting them to different values with the trainer class, like 2 or 0.0001, but they keep showing 1. I verified that the values 2 and 0.0001 indeed were used by the net.
Might this be a bug in dlib's dlib::net_to:xml function?
Those values apply for every layer and are independent from the trainer-values. The layer parameters are relevant for optimzers like the Adam Optimization Algorithm:
https://machinelearningmastery.com/adam-optimization-algorithm-for-deep-learning/
you can change them by specifyng them in every layer.
So no it is not a bug.