Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing in flextables #243

Closed
heor-andreas opened this issue Oct 1, 2020 · 8 comments
Closed

Referencing in flextables #243

heor-andreas opened this issue Oct 1, 2020 · 8 comments

Comments

@heor-andreas
Copy link

Hi David,

I hope you are well.

We are working with flextable and officedown to generate Word reports of academic writing. As part of the writing we use references to academic papers. Some of these references will appear in tables. Using the markdown language these are entered as [@author].
When outputting such a table through kable, the references get interpreted correctly, however, when passing the same table with references through flextable these references do not get interpreted. See example below.
See picture below.
image

Is there a workaround to this or a quick way to get this feature implemented?

I have also tried to apply Word table styles to the markdown table (which doesn't change the formatting) and the printout of the data.frame (which adjusts the style, but doesn't interpret the references).

Looking forward to hearing your thoughts.

Thanks
Andreas

@davidgohel
Copy link
Owner

Hello,

Could you add a reproducible example?

Thanks

@heor-andreas

This comment has been minimized.

@davidgohel
Copy link
Owner

OK, I think the following code + 17-11-17-Zotero.bib.zip reproduces your issue.

This is a kable feature, I don't know yet if this can be implemented.

---
output: officedown::rdocx_document
bibliography: 17-11-17-Zotero.bib
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.cap = TRUE)
library(officedown)
library(officer)
library(readxl)
library(knitr)
library(flextable)
mydat <- structure(list(Bibcode = c("[@brookmeyer_forecasting_2007]", 
"[@hellmann_new_1935]", "[@becke_densityfunctional_1993]", "[@stephens_ab-initio_1994]"
), Author = c("Brookmeyer", "Hellman", "Becke", "Stephens"), 
    Rate = c(100, 50, 100, 20), url = c("http://www.alzheimersanddementia.com/article/S1552-5260(07)00475-X/abstract", 
    "http://scitation.aip.org/content/aip/journal/jcp/3/1/10.1063/1.1749559", 
    "http://scitation.aip.org/content/aip/journal/jcp/98/7/10.1063/1.464913", 
    NA), doi = c("10.1016/j.jalz.2007.04.381", "10.1063/1.1749559", 
    "10.1063/1.464913", "10.1021/j100096a001"), number = c(1, 
    2, 3, 4)), row.names = c(NA, -4L), class = c("tbl_df", "tbl", 
"data.frame"))
```

This is a kable table.

```{r echo=FALSE}
kable(mydat)
```


This is a flextable

```{r echo=FALSE}
flextable(mydat)
```

17-11-17-Zotero.bib.zip

@heor-andreas
Copy link
Author

heor-andreas commented Oct 1, 2020

Thanks David,

I've done some investigating and am wondering if this somehow has to do with the way the flextable object is getting passed through to pandoc. I think pandoc is where the reference conversion happens.

In the code above I have just added this html code as plain text

<table>
<thead>
  <tr>
    <th>reference here:</th>
    <th>[@hellmann_new_1935]</th>
  </tr>
</thead>
</table>

when I knit this using the knit button in RStudio I get the kable tables done right, the flextable not interpreting the references and the bit I added in the html code at the end is also correctly converted to a reference. So it seems that things within the html arguments get parsed through the bibilography building part. In other words the fact that flextable generates html code does not seem to be the problem.

I then tried kniting to .md file. I can then see that the references in both the flextable html and the raw html at the end of the code are the same thing.
image

when I now knit this .md document to .html (clicking the preview button in RStudio) I get the references correctly done in flextable as well.
image

makes me wonder if the flextable code bypasses some of the pandoc processes?

@davidgohel
Copy link
Owner

davidgohel commented Oct 1, 2020

flextable doesn't require pandoc, it does not use pandoc to produce the code. To enable this feature, it has to be coded somewhere (maybe with ftExtra from @atusy).

@atusy
Copy link

atusy commented Oct 2, 2020

@heor-andreas

https://github.com/atusy/ftExtra does support Pandoc's markdown partly, but not citations.
Although I'm not sure if it is even possible, feel free to open an issue as a feature request.

Thanks for mention @davidgohel

@atusy
Copy link

atusy commented Oct 22, 2020

@heor-andreas

This feature is experimentally implemented by atusy/ftExtra#27

See example at https://ftextra.atusy.net/articles/format_columns.html#citations

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants