R ReporterRs Package - Add text after bookmark - r

I'm creating a tool to automatically generate reports for people in the office using the ReporteRs package in R. We have a standard set of tables/graphs, but the number of times a single table or graph may appear will vary from person to person. Due to this, I cannot make a single template with a fixed number of bookmarks.
I was hoping to get around this by having a bookmark on the first figure title and then repeatedly adding figure titles and graphs/tables underneath that one bookmark.
The 'addParagraph' function will only replace the bookmarked paragraph, so it will not work. I also tried replacing the bookmarked paragraph with a set of paragraphs, but since I have to alternate text/tables the bookmark gets placed onto two paragraphs after the first iteration and does not work after that.
Is there any way to simply add a piece of text after a bookmarked paragraph?

No that's not possible with ReporteRs. Maybe you could use package officer instead, cursor_* functions would help you.

Related

Is there a way to change the numbering of a five level header in R bookdown?

I am creating a textbook in bookdown and I would like to use a five level header to mark the homework problems. I am using a 5 level header (##### Header Name) because it is the next level header that has not been used yet. What is happening when I write the code is it appears with “1.2.0.0.1 Homework Question”. I would like it to look like “1.1 Homework Question”, but I have not found a way to change the five level header using css style changes. I would like the first number to be associated with the chapter and the second number to be associated with the homework question number. I wish I could upload a picture of the problem, but I am unable to do so.
I have tried using a counter to change the five level header in the css file. I have been able to change the color and the size, just not what appears with the numbering.

Is there a way of highlighting an entire code block loop in R, particularly RStudio?

I'm using RStudio 1.4.1106 for MacOS.
I'm continuing with writing my package functions. Some of them are quite long and involve branching methods depending on the nature of the input data. The branching involves if loops, and there are sub-if loops as well.
I comment the close brackets so I can back track to the start line of the loop (I don't use line numbers because I am frequently modifying code and the line numbers change). My current method to verify I have the correct loop selected is to go to the left of the close bracket and then identify the open bracket by the fact it is highlighted.
Is there a method of highlighting an entire loop code block? In particular, this would make it easier for me to comment out an entire block of code without worrying I have commented out too much or too little.
There are a few things that will make your life easier:
There are arrows next to the line numbers that will collapse a code block (I think determined by the braces {}). You can collapse from the top (e.g. line 109 in the screenshot attached) or the bottom (line 125 in the screenshot).
The other thing that can help if you want to examine code within a block is that double clicking just before or after the opening or closing brace will highlight all the code enclosed by the matching braces. See second screenshot below: .
Edit: Just noticed the comment - as mentioned you can also highlight code while the section is collapsed, and it will stay highlighted when expanded.

How to get data from website with interaction

I'd like to get data with R from following website: Website MFarm
I'm wondering if there's a chance to get them from R or I must use something else (e.g. Selenium, or Python) ?
Note that:
Needed data is the plot trend. This shouldn't be an issue, as it's only about getting a html attribute, and then to re-elaborate numbers within R.
Data are shown in the page not immediately, but only some seconds after the page is loaded. So some waitfor() function shall be used
There are 7 tabs. I need data from all of them. An interaction is therefore needed.
There's a combo box and a text box with parameters I've to choose

Is it possible to get RStudio to show function arguments and descriptions for custom functions?

The code completion in RStudio is great, and I really like how a popover appears to describe the arguments for the function inputs. For example, if one types matrix( and then presses "tab", a list of arguments for the matrix() function appears, along with a description of the input. Say, nrow= is selected, then the adjoining window describes the nrow input as "the desired number of rows.".
Can I get RStudio to do this for my custom functions? Would I have to create a package to achieve this effect?
Say I have a file full of custom functions, myCustomFunctions.R, and I store all my miscellaneous helper functions in there. I want to be able to add meta data for my functions so that this helper window also describes my function inputs.
To add to Hadley's answer in the comments, Rstudio is mining specific portions of the help files to generate the helper window. Specifically, tabbing before the parentheses brings up the "Usage" and "Description" sections and tabbing inside the parentheses or after a comma brings up the "Arguments" section. Therefore, not only does a package need to be made, but the help files must be generated to take advantage of this feature.
Following up Hadley: even if the functions are only for your own use, it's worth package-izing them. You will then get a lot of useful stuff for free, above and beyond the package documentation system: things like version control, unit testing, portability, shareability ... I could go on. There's a small potential barrier which you have to get over before you can get back to the fun part (i.e. hacking your own neat stuff), but it's worth the investment of time.
Hadley has public-spiritedly put his Packages book online with step by step descriptions of how to access all the goodies I've mentioned. Hopefully you'll decide it's worth paying for (I did).

Mathjax loading issues

I've a web page that renders latex equations using mathjax.
In order to load the equations faster, i'm trying to avoid the preprocessing step, by replacing the
math delimiters by <span class="MathJax_Preview">[loading...]</span><script type="math/tex;"> latex equation here </script>
But the problem is; while rendering, the html entities that comes within the equation are shown as such and hence the equations
are not rendered properly.For eg, '&' is used for alignment of multiple steps. But it is displayed as &
Replacing the math delimiters by <script> tag is done dynamically. If i remove this step, then the said issue is not there and html entities within equation are rendered properly.
How can i solve this?
My ultimate objective is to make the equation load faster.
Show a preloder like [loading...] until the maths is typeset fully.
Thanks,
LS Developer
Note that the contents of the <script type="math/tex"> is TeX (or LaTeX), not HTML, and so HTML entities should not be included there. The contents of any <script> in HTML is CDATA, and so no processing, including conversion of entities, is performed within it.
If you are using numeric entities like A or A then it is easy to replace those by the characters they represent. If you are using named entities, then you will need to translate them into their characters via a table lookup or other process. Better yet would be not to put in entities in the first place. Can you not perform that step? (I'm assuming that is done outside of your control.)
Note that the preprocessing step in MathJax is actually quite fast, and is not likely to be a bottleneck unless you have an enormous number of equations. It is the conversion to HTML that is the time sink. If you aren't using one of the combined configuration files, you will probably get a better improvement simply by moving to one of those than by removing the preprocessor step. If you already are using a combined configuration file, but aren't using the "-full" version, then moving to that will also speed up the processing of the math (since you won't have to wait for the input and output jax to load when they are first used).

Resources