Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yonicd/captions
https://github.com/yonicd/captions
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/yonicd/captions
- Owner: yonicd
- License: other
- Created: 2020-05-21T10:34:09.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-14T01:57:49.000Z (over 4 years ago)
- Last Synced: 2024-08-13T07:14:59.942Z (3 months ago)
- Language: R
- Size: 13.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - yonicd/captions - (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# captions[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
The goal of captions is to create Figure and Table environments mechanistically for TeX documents
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(captions)
## basic example code
```## Figures
### Include Figure
```{r}
captions::include_fig()
```### Wrap Figure
```{r}
captions::wrap_fig()
``````{r}
captions::include_fig(FIGPATH = 'mypath.pdf')%>%
captions::wrap_fig(CAPTION = 'My Caption')
```### Subfigures
```{r}
list(captions::sub_fig(SUBFIGPATH = 'mypath.pdf',SUBLABEL = 'fig:sub1'),
captions::sub_fig(SUBFIGPATH = 'mypath2.pdf',SUBLABEL = 'fig:sub2')
)%>%
captions::wrap_fig(CAPTION = 'My Caption')
```## Tables
### Wrap tabular lines
```{r}
mtcars%>%
head()%>%
knitr::kable(format = 'latex')%>%
captions::wrap_tbl()
```Create some files in `tempdir/deliv/table`
```{r}
td <- file.path(tempdir(),'deliv/table')
dir.create(td,recursive = TRUE)tf1 <- file.path(td,'mtcars_head.tex')
file.create(tf1)tf2 <- file.path(td,'mtcars_tail.tex')
file.create(tf2)mtcars%>%
head()%>%
knitr::kable(format = 'latex')%>%
as.character()%>%
captions::wrap_tbl()%>%
cat(file = tf1)mtcars%>%
tail()%>%
knitr::kable(format = 'latex')%>%
as.character()%>%
captions::wrap_tbl()%>%
cat(file = tf2)
```### Wrap include call to table file
```{r}
tf1%>%
tex_include()%>%
captions::wrap_tbl()```
## Populate an Output file
```{r}
table_file <- file.path(tempdir(),'deliv/tables.tex')
file.create(table_file)
# Names of the elements in the caption vector is the same as the files in deliv/table
caption <- c(
mtcars_head = 'First 5 Rows of mtcars',
mtcars_tail = 'Last 5 Rows of mtcars'
)captions::tex_update(
tex = captions::tex_tables(caption,table_files_dir = td),
file = table_file,
section = 'Example',
type = 'Tables',
overwrite = TRUE)```
```{r}
cat(readLines(table_file),sep = '\n')
```