Skip to content

Instantly share code, notes, and snippets.

@mgei
Created April 2, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgei/32102a1c89b49da21516bb2eed80385e to your computer and use it in GitHub Desktop.
Save mgei/32102a1c89b49da21516bb2eed80385e to your computer and use it in GitHub Desktop.
R function to build a local URL for RMarkdown
library(tidyverse)
localurl <- function(document, path = ""){
path <- str_remove_all(path, "/$|^/")
document <- str_remove_all(document, "/$|^/")
path <- file.path(path, document) %>%
str_remove_all("/$|^/")
document <- last(str_split(path, pattern = "/", simplify = T))
return(paste0("[", document, "](", path, ")"))
}
---
title: "Untitled"
author: "Martin"
date: "2 April 2019"
output: pdf_document
---
```{r setup, include=FALSE}
source(localurl.R)
```
We have evidence, see `r localurl("../data/evidence.pdf")`.
We also have more evidence here: `r localurl("moreevidence.pdf", "../data/")`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment