yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.37k stars 874 forks source link

improper R kable output in console #2229

Closed antoine4ucsd closed 1 year ago

antoine4ucsd commented 1 year ago

Hello I am having issues with kable on my mac . the output is not really what I would expect. not sure how to explain it. for example. If I run

knitr::kable(t,caption="finalfit table")

I would expect

image

but I got

image

not sure if this is related but I also get this kind of errors:

sh: line 1: 24442 Killed: 9               '/Users/myself/.virtualenvs/r-reticulate/bin/python' '/Users/myself/Library/R/x86_64/4.2/library/reticulate/config/config.py' 2> /dev/null
Error in python_config_impl(python) : 
  Error 137 occurred running /Users/myself/.virtualenvs/r-reticulate/bin/python: 
Calls: do.call ... <Anonymous> -> <Anonymous> -> python_config -> python_config_impl
In addition: Warning message:
In system2(command = python, args = shQuote(script), stdout = TRUE,  :
  running command ''/Users/myself/.virtualenvs/r-reticulate/bin/python' '/Users/myself/Library/R/x86_64/4.2/library/reticulate/config/config.py' 2>/dev/null' had status 137
Execution halted

all advices are welcome! thank you

cderv commented 1 year ago

You may have something in your document that is changing the default format for kable() - this should output markdown

> knitr::kable(head(iris), caption = "An example table caption.")

Table: An example table caption.

| Sepal.Length| Sepal.Width| Petal.Length| Petal.Width|Species |
|------------:|-----------:|------------:|-----------:|:-------|
|          5.1|         3.5|          1.4|         0.2|setosa  |
|          4.9|         3.0|          1.4|         0.2|setosa  |
|          4.7|         3.2|          1.3|         0.2|setosa  |
|          4.6|         3.1|          1.5|         0.2|setosa  |
|          5.0|         3.6|          1.4|         0.2|setosa  |
|          5.4|         3.9|          1.7|         0.4|setosa  |

The default format can be changed by option knitr.table.format and seems to have been set for html for your session. Do you use kableExtra for example ? It can do that I think when you load it.

not sure if this is related but I also get this kind of errors:

This is an error from reticulate which is not finding your python correctly. reticulate is used when you are using Python in your Rmd document.

antoine4ucsd commented 1 year ago

thank you for the quick reponse! I only set the following in my code

knitr::opts_chunk$set(echo = T,message=FALSE )

I did not load kableExtra. However, if I open a new session of R and only type your example, it seems to work well. if I install the pal package, it gives me the following

> pal::knitr_table_format('simple')
[1] "html"

what would you recommend? thank you

antoine4ucsd commented 1 year ago

this works!

options(knitr.table.format = "simple") 

thank you

cderv commented 1 year ago

You can also pass to the to the format argument in the function.

Also I don't know about the pal package but they probably are doing the same as kableExtra and change the default at loading time.

I'll close this as you know how to change now

github-actions[bot] commented 11 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.