Code Monkey home page Code Monkey logo

kfigr's Introduction

kfigr

CRAN_Status_Badge Project Status: Active R-CMD-check CRAN_Download_Badge

A streamlined cross-referencing system for R markdown documents that integrates with the knitr package. It defines a hook for anchoring code chunks and tracks chunks for cross-referencing document elements like figures, tables and code blocks.

{kfigr} works only for markdown-->HTML. If you need support for markdown-->PDF, see the {bookdown} provides advanced labeling and cross-referencing functionality with pandoc that works with both HTML and PDF outputs.

kfigr's People

Contributors

mkoohafkan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kfigr's Issues

using anchor eliminates figure captions

When I compile this:


---
output: 
  html_document:
    fig_caption: yes 
    dev: CairoSVG

---

```{r}
library(kfigr)
```
```{r test,echo=FALSE,fig.cap="test caption"}
plot(cars)
```

I get figure captions, but when I compile this:


---
output: 
  html_document:
    fig_caption: yes 
    dev: CairoSVG

---

```{r}
library(kfigr)
```
```{r test,echo=FALSE,fig.cap="test caption",anchor='figure'}
plot(cars)
```

...I get no figure caption. I'm using:

      Package Version 
kfigr "kfigr" "1.2"   
knitr "knitr" "1.10.5"

under

> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)

Thanks!

Link not displayed in PDF

I'm trying to use kfigr to produce links to figures/chunks, but when I Knit PDF using knitr only the figure/chunk number is shown and not the link to the figure. It works just fine when I Knit HTML, but I'd like to use this on a PDF.

Deal with `rmarkdown`'s option wiping

rmarkdown resets the knitr options via opts_knit$restore() after rendering a document so that options changed during one render don't persist across the next document. However, this means that the options and hook definition set by kfigr also get wiped. I need to create a kfigr.initialize() function that users can call at the start of a document to set the anchor hook and kfigr options.

"First reference must define the type." on Check

I've got a bunch of vignettes that I'm converting from Rnw to Rmd thanks to this package. Individually, they are all Kniting just fine. However, when I use devtools::build_vignettes() or just run a 'check', I get errors:

failed with diagnostics:
First reference must define the type.

Each vignette starts like this:

---
title: "xxx"
author: "xxx"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
  rmarkdown::html_vignette:
    fig_height:  6
    fig_width: 6
    toc: yes
    fig_caption: yes
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{xxx}
  \usepackage[utf8]{inputenc}

---

```{r setup, echo=FALSE, warning=FALSE, message=FALSE}
library(knitr)
library(kfigr)
library(rmarkdown)
opts_chunk$set(message=FALSE,warning=FALSE,dev="png")
opts_knit$set(eval.after='fig.cap')

Then when I make my figures, I create the chunk like this:



```{r chunk1, anchor="figure", fig.cap=paste0("**Figure ** ",figr('chunk1'),": Dummy plot.")}
plot(1)

Any idea why it would fail during check (with that error) and not when just using the 'Knit' RStudio button? I realize there could be a lot of reasons un-related to your package, but that error I think is unique to kfigr.

Putting 'Figure X: Description' into the figure caption automatically

Thanks for making this package. It is quite nice. I notice that if I don't specify a caption, I get a default caption related to the chunk name. What I would like to do is capture the text part generated by r figr('chunk-name', type = 'figure') which would be, for instance, "Figure 1" and use it as part of the figure caption. For example, if I said fig.cap = "descriptive caption" it would be really nice if kfigr turned the figure caption into "Figure 1: descriptive caption". I hope this is clear. Yuhui has something similar, but it would operate independently and the numbering may get out of register.

.docx implementation?

Really nice package. Do you have any plans for a .docx implementation? It would be massively useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.