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
Related
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.
I am putting an assignment together in R Markdown to PDF (through Latex) and been using xtable to nicely format my output. The below code generates a small table that I would like to align right in the document and have text wrap around it. Is there a way to achieve this?
summary.table <- xtable(ddply(aircon, ~when, summarise, Mean=mean(hours), StdDev=sd(hours)), caption="Mean and Standard Deviation (in Hours) Before and After Change")
print(summary.table, include.rownames=FALSE)
Given the update regarding using LaTeX to do the wrapping, how could I write this in R Markdown to take advantage of this? I have tried to print inline using r <code> but that didn't work.
I guess you could add the begin/end wraptable commands in the r-chunk that creates the table, like this:
cat("\\begin{wraptable}{r}{5.5cm} \n")
...
print(summary.table,...)
cat("\\end{wraptable} \n")
You can use the Includes mechanism documented here, to include a custom header.tex which would contain usepackages, etc.
I can't find a method to remove the hash marks and row numbers from dataframes outputted to a word document in R markdown. I'd like to be able to present only the data without those features
The knitr website and specifically the page on Chunk options suggests the use of a separate chunk (before your want to display a data.frame in this manner) to change the default for the chunk option comment, perhaps like this:
```{r global_options}
opts_chunk$set(comment = NA) # default value is '##'
```
to disable the inserting of comment characters on output. Realize that this setting of the comment option is applicable to all chunks that follow this chunk; this chunk itself will not be affected by it.
This does give the textual representation of the data.frame (as if it were on the terminal), and not a more refined representation. I second #PierreLafortune's suggestion to look at knitr::kable.
Check out the sjPlot package and specifically the view_df function
Given a linear model:
fit <- lm(mpg~., mtcars)
I tried `r formula(fit)` to print the model/formula inline, but trying to knit the RMarkdown file to PDF or HTML gives errors (error in vapply...)
If it do the same thing inside a triple quoted code chunk, it works fine:
```{r}
formula(fit)
```
formula(fit) prints the formula on the R interpreter as I would like.
Is there a limitation to what can be done in an inline code chunk, or am I missing something?
I don't know why exactly, but I think the issue lies in the structure and formatting of a formula-object. I'm guessing that the objects get converted to character in order to be printed. This is why it works (albeit in a weird sequence) for one independent variable, but doesn't work for multiple independent variables.
A workaround is to use
`r format(formula(fit))`
As inline code, it gave me the desired result.
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