While knitting an R markdown document the inline code is printed 'as is', for example:
- The number of patients in the dataframe is `n_distinct(med1$patients)`.
Is knitted exactly the same:
The number of patients in the dataframe is n_distinct(med1$patients).
The code is not evaluated, rather the text is formatted as code. In a previous question someone suggested adding brackets but it doesn't work for me.
Any suggestions will be much appreciated.
I stumbled across the solution. I had to write it this way:
The number of patients in the data frame is `r n_distinct(med1$patients)`.
With the extra R in the code made it run as desired.
Related
Can anyone help me out?
I have to automate some reports, with R Markdown, of the company I work for.
To do so, I have to create headings with the names of forest gardens, deppending on the forest gardens that were evaluated last month.
The problem is that the numbers of forests gradens evaluated every month is not the same.
So, I added a condition to run on chunk option "eval" to create that heading deppending on the number of the evaluated forest gardens (it's ok until here).
To do so, I wrote this code:
```{r eval = cond_n1, results = 'asis'}
cat('<h4 class = "hortos"> 4.1. `r unique(tabela_por_talhao$NM_HORTO[1])`</h4>')
```#end
But when I knitr the document every thing works very fine, but the inline code that I inserted in this heading doesn't, it prints the code literatelly (without execute).
Is there any way to do what I want?
OBS: I only added the "#end" to the end of the chunk because otherwise it won't show here the whole code.
I am using R markdown with rmarkdown::render(). The problem I am having is that all inline latex equations gets displayed in a new line in the resulting html document.
For example, the .Rmd file containing the following:
numeric observations $y_1,\dots y_T$ up to some time $T$
turns out line breaks before y_1 and before T.
Has anybody had this problem and/or knows how to fix it?
Thank you in advance,
Giovanni
I am using a dataframe (called "Survey") from survey data in which the final question is an open comment box. Hence, my final vector in the dataframe consists of string data. I am attempting to create a report in R Markdown in which each comment (each row of that string vector) appears on a separate line in the outpout. My first attempt was to simply insert the variable name into a line of r code within my markdown window, as such:
r Survey$Comments
This resulted in the comments all appearing in one big chunk, with a comma separating each comment. I then attempted to use the "cat" function as follows:
r cat(Survey$Comments, sep="\n")
When I run this code in my regular R console window (not in R Markdown), it gives me the output I want (each comment on its own line), but does not work the same way when I run it in markdown. I'm at a loss as to how to get the output I need, and thought I'd turn to the broader community to see if anyone has any advice.
We can use writeLines.
writeLines(c("Line1", "Line2", "Line3"))
Line1
Line2
Line3
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
Is there a clean solution for numbering lines in code chunks in R Markdown?
There is some relevant information here, it solves this problem for .Rnw files, however I'm looking for a solution for .Rmd files (with HTML output). Preferably the solution would provide continuous numbering within the document, instead of starting over at each code chunk. This would allow for referencing an earlier code chunk via a line number.
I am also looking for a solution that doesn't require repeating the code chunk (like here) since that seems error prone (inevitably there will be cases where one chunk gets updated and the other isn't).