0

I kind of know the answer, which is render(). However, when I render the code below, the output is not consistent with the one that I would get by simply pressing knit. In fact, the table is not rendered as expected from the function kable.

---
title: "Untitled"
output:
  pdf_document: default
  html_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown
```{r results='asis'}
library(knitr)
library(dplyr)

print_kable <- function(species) {
        iris %>% filter(Species == species) %>% 
            summarise(avg=mean(Sepal.Width)) %>% 
            kable(caption=paste('Results for', species)) %>% print
        }

ff <- lapply(c("setosa", "versicolor", "virginica"), print_kable)

```

To call the renderer I use rmarkdown::render('testLookKable.Rmd', output_dir = 'standardReports/', runtime = 'static', output_format = 'pdf_document').

This is how the tables look like when I press the botton to knit to pdf:

enter image description here

And this is how to it looks like when I render() by typing in the function

enter image description here

What I am trying to achieve is the first output, but rendering by explicitly running the function rather then pressing the botton.

From sessionInfo():

R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.4
rmarkdown_1.5
knitr_1.15.1 
Dambo
  • 3,318
  • 5
  • 30
  • 79
  • I'm having a hard time replicating what you are describing. What versions of the rmarkdown/knitr packages do you have installed? – MrFlick May 10 '17 at 05:23
  • Possible duplicate: http://stackoverflow.com/questions/22531084/what-is-the-code-behind-the-knit-html-button-in-rstudio-0-98-501 – MrFlick May 10 '17 at 05:31
  • 1
    Please add actual and expected output to the question. In general, [this](http://stackoverflow.com/questions/34591487/difference-compile-pdf-button-in-rstudio-vs-knit-and-knit2pdf) might be interesting for you. – CL. May 10 '17 at 07:15
  • @MrFlick Thanks, I have edited my question. – Dambo May 10 '17 at 14:46
  • Using exactly your code, the same version of R, the same version of knitr and rmarkdown (although on Windows), I cannot reproduce this. – CL. May 10 '17 at 15:55
  • 1
    @CL. Do you mean that you cannot reproduce any of the two outputs because you get an error, or that everything works fine and you get the output as in my first screenshot? – Dambo May 10 '17 at 16:16
  • 1
    Sorry for being imprecise. I meant I cannot reproduce the problem, I always get the correct output as shown in your first screenshot. – CL. May 10 '17 at 16:29

1 Answers1

1

I was getting errors about pdflatex not being found (despite multiple versions of found by locate. After setting my current version of TexLive to 2016,

machine-name:~ username$  texdist —-current
machine-name:~ username$  pdflatex -v
# pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016)

I still needed to do this (copied from an answer on SO):

 sudo ln -fhs Distributions/.DefaultTeX/Contents/Programs/texbin /Library/TeX/texbin
 echo "/Library/TeX/texbin" >~/Desktop/TeX
 sudo cp ~/Desktop/TeX /etc/paths.d/TeX
 echo "/Library/TeX/Distributions/.DefaultTeX/Contents/Man" >~/Desktop/TeX
 sudo cp ~/Desktop/TeX /etc/manpaths.d/TeX
 echo /Library/TeX/texbin

I now get sort of a combined version of your two images:

enter image description here

I had also edited PATH to remove the pre-El Cap item: usr/bin/texbin and put in /Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:. None of which worked. (I'm not using RStudio.)

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • I didn't notice any specific error, but your post made me realize I was running an older version of TexLive. After updating, it works fine, meaning it gives the output that you posted. – Dambo May 11 '17 at 21:21