markdown insert tabulator (R) - r

Is there a way to insert tabulators in R markdown code?
I just want to show sth. like
attendees: 33
sick leave: 1
presenters: 5
Text is Markdown text, numbers are inline R code. Simply putting spaces does not work, since there is a variably spaced font.
Ideally working for both HTML and PDF output. (I work on Win-10 in RStudio)
All my searches ended up in (a) creating markdown tables (too big), or (b) how to create tabs for tabbed browsing, much more complicated. I tried \t and \t, does not work.

I use either the RStudio add-in BeautifyR which has a nice Beautify Table. Got the top banner under Tools there is the Add-ins button load BeautifyR.
Then there is also using Kable. Look for the R packages and install: knitr::kable and kableExtra.

Related

Less space between letters and units in rmarkdown (pdf and docx output)

I cannot find any information about spacing between letters in R Markdown. All I found only were questions about vertical spacing. I basically have two issues:
In LaTeX I usually use the siunitx package to correctly typeset numbers and units. I can of course use this in R Markdown as well if I load the package with \usepackage{siunitx}. But this does not output to the docx format, only to pdf. That brings me to my other question...
So I tried using different spaces of LaTeX to display numbers and their units with at least less space, e.g. writing 40\,m^2 to display 40 m² (in LaTeX I would use \SI{40}{\square\meter}). However, apparently R Markdown does not handle the \, nor \; at all, not even in the pdf output.
Question: What is the correct way to add smaller spaces between letters in R Markdown? (irrespective of output format!) How do I replace the \, command?
And: Is there a way to handle units nicely using R Markdown? I have found this question on the R units package, and I could live with it. That is, if I want to write hardcoded numbers like 40 m² I would have to use something like`r format(set_units(40, m2))`,right?.
Have you tried adding thin spaces using Unicode chars? For example, this page http://jkorpela.fi/chars/spaces.html suggests that "\u2009" and "\u200A" should display as thin spaces.
When I try this with a PDF document (using latex_engine: xelatex to handle Unicode), this is what I see:
It also appears to work with HTML and Word output.
Edited to add:
To be clear, this needs to go through R. If you want it inline, use code like this:
This is standard spacing: 40 m²,
this is narrow `r knitr::asis_output("40\u2009m²")` spacing.
This produces this output in PDF:

Markdown and outline an R script

I am using Emacs for an R-script with markdown using oxygen comments. With rmarkdown::render() I produce either a HTML or pdf file. Works great.
However, it would be great if I could use outline mode for headings in this file (coloured differently and collapsing or showing stuff). I have searched the internet but haven't found a solution, how to make this work.
An example would be (R-File):
#' # Heading 1
#' some test
t <- c(1,2)
#' ## Heading 2
#' some more text
s <- c(1,2)
It would be nice, if I could collapse it and have different colors for the heading levels.
HTML
One possibility is to use knitr package to render the R markdown.
In addition it is possible to feed it a CSS file that will allow you to style headings (like colors). This answer Custom CSS with knitr and markdown in R may be useful to help you achieving this.
If you are familiar with css, you can always add the collapsing effect. If you aren't I suggest to have a look at this: http://www.webdeveloper.com/forum/showthread.php?77389-Expand-Collapse-Paragraph
Twisting the idea around would be to use Shinypackage to create an interactive page with R code, however it is a bit far-fetched considering that it started from a Markdown.

Is it possible to use Rtable (FlexTable) to generate a pdf table in RMarkdown

I'm creating some RMarkdown reports and want to be able to extensively format a table. I've tried working with kable and pander but they don't give me enough functionality (for example to use colors for rows).
I ran across the Rtable package (that goes along with the FlexTable object of the Reporters package) which allows significant customization. The only problem is that I can so far only get my table to show up when I knit to html, when I knit to pdf (what I need) I just get an unformatted list of text instead of my table.
here's what my code looks like (summaryterms is a dataframe)
setZebraStyle(FlexTable(summaryterms[c(5,1:3,9:11,14)]),odd = "#DDDDDD", even = "#FFFFFF" )
Is there anyway to use the FlexTable object with a pdf report?
Thank you so much for the help
Also, I'm open to any and all other solutions to format tables in rmarkdown, I'm not married to using flextable.

Lyx - how to create sections without titles

I'm currently looking into lyx because I'm starting to get fed up with writing LaTeX by hand. The problem is, LyX seems to be a bit opiniated about how sections should be written - I'm used to writing
\subsection{}
\subsubsection{}
...
\subsubsection{}
etc., because in the documents I'm writing I don't want titles for my sections. I just want them to be numbered. LyX doesn't seem to like that though, and ends up deleting my sections (and subsections, and subsubsections) when I don't have any text in their titles.
I can just insert a hard space, but this feels kind of weird. I don't understand why lyx wouldn't just let me hit enter and be done with it.
Try to us a 'hard space' as title of the sections, through <Ctrl>+<space>, that should do the trick (it's the keyboard shortcut for LaTeX's "~").
You can insert Evil Red Text (raw LaTeX commands) in LyX. Look for Insert -> TeX Code menu. I just tried it and inserted \subsection{} inside the ERT, and it compiled successfully and showed the section numbers.

Wrap text in dataframe in R- or in output cell to Word

I am working in R, trying to export a dataframe to MS Word. I am using R2wd and would like a dataframe to export to MSWORD, and wrap a long string of text within a cell. Is that even possible?
Bare minimum at least pass a command from R to set the height of each row to fit the contents of the cell...
I don't see any demos or documentation but surely somebody must need to do that sometimes!
I'm not sure if this is exactly what you want, but you could export the data.frame to a .Rnw file with xtable, process it with Sweave, and then run the .tex file through latex2rtf. Unfortunately, latex2rtf does not format tables nicely . . .
You could do that with the odfWeave package, which is similar to Sweave, except for you can make dynamic odt (Open Document Format) documents. Well, the package does not generates a doc or docx file, but the odt can be opened without problem in the newer versions of MS Office (2007 and above), and in OpenOffice - so might work for you.
The main advantage of the package is that you can define the styles of the table (header or every cell of the table) to your taste. See the examples in the package's archive for further information.

Resources