-
Hello. Details
---
format: pdf
---
```{r}
library(tidyverse)
library(kableExtra)
x <- c(3, 1, 2)
Table1 <- data.frame(A = x, B = letters[x])
x <- c(11, 16, 21)
Table2 <- data.frame(C = x, D = letters[x])
tab <- "Table1"
```
OK with "#| label: tbl-tables"
```{r}
#| label: !expr paste0("tbl-", tab)
#| tbl-cap: !expr paste("This is", tab)
#| tbl-subcap:
#| - "first"
#| - "second"
tbl <- get(tab)
kbl(tbl)
tibble(attribute = names(tbl)) |>
unnest(cols = c(attribute)) |>
mutate(kind = typeof(attribute)) |>
kbl()
``` |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Could you format properly your post? In its current shape it is not quite legible. See https://quarto.org for your question about upgrade. You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````qmd
---
title: "Reproducible Quarto Document"
format: html
---
This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.
```{r}
plot(cars)
```
The end.
```` |
Beta Was this translation helpful? Give feedback.
-
Many thanks!
I could imagine but I do not know how I could find the answer you are
giving me.
While compiling the question in knitr GitHub site, a question
tightly related to mine came up and I discovered that using
knitr::knit_extend() it is possible (though not straightforward at all!)
to obtain my goal:
"produce many cross-referenceable nicely formatted (with label, cap and
sub-caps) table pairs, writing the code only once."
Roberto
Il giorno lun 17 lug 2023 alle ore 15:40 Christophe Dervieux <
***@***.***> ha scritto:
… FWIW *knitr* does not support using a R object / expression as a label.
This is because the labels are determined before any code chunk is
evaluated (i.e., they are determined at the parsing stage):
***@***.***/R/parser.R#L197-L198
<https://github.com/yihui/knitr/blob/0e9bb8bc8cd77b2b8ace872637bb86a5b6d54bcb/R/parser.R#L197-L198>
When parsing the document, the parser doesn't know the value of any objects.
Related discussion: rstudio/bookdown#1419 (comment)
<rstudio/bookdown#1419 (comment)>
—
Reply to this email directly, view it on GitHub
<#6210 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEAKXD2YUX6XJ4TUZOOSV3DXQU6FTANCNFSM6AAAAAA2KFFVTA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Roberto Scotti
<https://scholar.google.it/citations?hl=en&user=EgZYcIAAAAAJ&view_op=list_works&sortby=pubdate>
- Nuoro Forestry School
<https://www.facebook.com/NuoroForestrySchoolUniSS/>
Dip. Agraria <https://www.uniss.it/ugov/person/2496> - ***@***.*** ORCID
iD <https://orcid.org/0000-0001-7394-4473> Publons
<https://publons.com/researcher/1104101/roberto-scotti/> IRIS
<https://iris.uniss.it/cris/rp/rp02644>
--
--
*Dona il 5x1000* all'Università degli Studi di Sassaricodice fiscale:
00196350904
|
Beta Was this translation helpful? Give feedback.
Many thanks! Your redirection towards knitr has been the key to solve my problem.
I immediately referred to GitHub Kintr site where I found that an analogous question had already been answered.
I developed my solution based on https://stackoverflow.com/questions/12095113/r-knitr-possible-to-programmatically-modify-chunk-labels
Excuse me again for the errors.
Roberto