Flextable export and image width issues - r

I am producing some tables which I now wish to incorporate into a latex document (not knitted by R but externally built).
I gather that flextable can now produce latex, but is this ONLY for knitting or can I export it somehow?
Failing that I'm guessing that exporting as an image might be the next best thing?
The tables though are quite wide and I intend to use them in the document rotated (landscape). How do I specify the width of the final image I need, and the DPI I'd like?
Finally, whilst testing all this in an Rmd script, my table columns are getting wrapped as I increase the number of columns. Is there some way to increase the maximum width available to print?
Updates:
Adding to the .rmd script
{r plotting fig.width=12, fig.height=8, dev='png'}
does NOT fix the visible porthole size.
It would appear that when flextable thinks it's running out of room it starts breaking the column contents at spaces, overriding the width() specification. Replacing the spaces with non-breaking spaces seems to restore some order here.

Related

How to made a flextable table in the same MSWord style than tables made with knitr::kable, or how to define interlines?

After kniting a Bookdown project into a .docx file, the - excellent - flextable package made tables in my .docx document with MS-Word 'Normal Style', which has very large interline and is supposed to define the text, nor the tables' cells.
Please, how can I made a flextable table with 1.0 interline or how can I made the flextable tables in the same style than the knitr::kable() ?
The knitr::kable() behavior is to define the MS-Word 'Compact Style' for the entire table, after knitting to .docx. This behavior of knitr::kable produce tables with simple interlines, in my case (vs. the 'Normal Style' for flextable tables with 1.5 interlines). The following image is an example of these differences, in my .docx output.
It seems that it's not possible to apply a MSWord style on a flextable object, and we have to set the police size and font by adding font(), etc. But flextable::padding(padding = 0) doesn't define interline. Maybe I'm wrong on this point ? There is a way to define interlines for a table, or set the same MSWord style for all the tables produced with flextable ?
Thanks a lot, un très grand merci.
It seems that the - wonderful - flextable package is now able to set interline efficiently, with flextable::line_spacing(). So, for a table with only a single line of text in each row (like in the example above), you have to add:
line_spacing(x = flextable_object, space = 0.8, part = "body")
This work well for tables with one single line of text in each cell. If there is several lines of text in a single row, be aware that flextable::line_spacing() affect the line spacing of these several lines of text in a row, in addition to the global line spacing between the lines of the table.
Thanks a lot David G.

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 output not fitting column

I'm writing an article in RStudio (global setting is using knitr) trying to make the output generated by a chunk of code fit the specification of the IEEE jornal, butthe output will wonder off the column (text is organized in two columns).
I've tried specifying the out.width of the code chunk with the column width (out.width="\columnwidth") but it doesn't seem to do much. I've also tried specifying the same parameter with "\linewidth" and "\textwidth" but still I get the same output to the pdf. I've also tried scaling down the size by puting in "%10" and "1%" but no sucess.
<>=
levels(classObito$estado_fisico)
#
Expected the output of the code chunk to fit into the column, but it wonders off the page or to the other column.
Solved with adding option(width="50") inside the code chunk

Style a kable table knitted to pdf

I'm using kable to output a table from a data.frame in a R markdown document that is parsed to pdf.
This is the output:
I would like to style the table. Specifically I'd like to:
Increase cell height. The padding argument passed to kable() function didn't have effect.
Make the headings bold. (No idea about this).
I call kaggle() in a function that is then called into the chunk in the .Rmd file.
Thanks for your help
I don't know whether you tried already, but the kableExtra package offers a lot more features than kable. You could simply pipe your kable call into row specifications with
%>% row_spec (0, bold = T)
I couldn't find an option for cell height there. In case you'd generally want to change it you could either pass it as an option into the YAML header or change the default.tex file.
Regards

knitr: Document does not change anymore

I have a .Rnw document in which I include childs. The childs produce tables via the 'latex' command of the Hmisc library in R.
When I make changes in the child documents, these changes do not anymore change the pdf document. My first guess was to use the chunk option 'eval=TRUE', but this does not change anything. Then, I saw, that the tables are actually saved to a .tex file with same name as the .Rnw document. I deleted this file and after compilation with knitr I got an error:
Error: Latexmk: Could not find file documentname.tex.
I assume, this is not the way to do it. Now I am out of ideas what to do. I appreciate some help on my problem.
Best
Simon
Allright, when trying to construct a simple example, I actually found out, that neither the packages I included nor the nesting of child documents interfere with the compilation via knitr. The reason was a simple error in the low-level .Rnw document, where a Hmisc latex table had a label, that missed a closing speech mark.
This causes then the output pdf not to change - I assume, that in this case the already constructed .tex file is included instead of letting knitr recompile the .Rnw documents and this hasn't changed since the last compilation?
What I wonder about is the different format of the landscape ctable in the document. Using a simple knitr document just with \documentclass{article} produces well placed tables. In my document using a template for the JFE, I get a table that extends over the whole page and even in footnotesize it is far away from the great appearance in the simple document. There is only a margin of less than half a cm on the right and the left. Page size is the same: both US letter... Can I probably control that via knitr or only via resizebox?

Resources