Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R markdown link is not formatted blue when knitted to pdf

for some reason no link in my R markdowns (rmd) is formatted blue. knitting the simple rmd below to pdf is leaving the text color black. only when hovering over it does one realize that it's actually a link. knitting it to html will make the link blue. of course I can use a latex wrapper but I wonder why that is?

sessionInfo() R version 3.3.0 (2016-05-03) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 loaded via a namespace (and not attached): knitr_1.15

RStudio 1.0.44

--- title: "R Notebook" output:   pdf_document: default   html_notebook: default ---  ```{r, echo=F} # tex / pandoc options for pdf creation x <- Sys.getenv("PATH") y <- paste(x, "E:\\miktex\\miktex\\bin", sep=";") Sys.setenv(PATH = y) ```  [link](www.rstudio.com) 

enter image description here

like image 969
Triamus Avatar asked Nov 30 '16 16:11

Triamus


People also ask

How do you Knit a PDF in RMarkdown?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

Why is my RMarkdown not knitting?

No Knit HTML button This means that RStudio doesn't understand your document is supposed to be an RMarkdown document, often because your file extension is . txt . To fix this, go to the Files tab (lower right corner, same pane as Plots and Help) and select the checkbox next to your document's name.

How do you hyperlink in R markdown?

Hyperlinks are created using the syntax [text](link) , e.g., [RStudio](https://www.rstudio.com) . The syntax for images is similar: just add an exclamation mark, e.g., ![ alt text or image title](path/to/image) . Footnotes are put inside the square brackets after a caret ^[] , e.g., ^[This is a footnote.] .

Why is Knit not working in R?

If a chunk works in R but not when you knit, it is almost always because you've changed a variable in your global working environment not using code in a chunk. Try restarting your R session and running each chunk sequentially to make sure all your variable values are up to date.


2 Answers

Add urlcolor: blue to the yaml.

--- title: "R Notebook" output:   pdf_document: default   html_notebook: default urlcolor: blue ---  ```{r, echo=F} # tex / pandoc options for pdf creation x <- Sys.getenv("PATH") y <- paste(x, "E:\\miktex\\miktex\\bin", sep=";") Sys.setenv(PATH = y) ```  [Link to R Studio](www.rstudio.com)  Bare urls will also be highlighted:  http://www.rstudio.com 

enter image description here

like image 141
eipi10 Avatar answered Sep 29 '22 14:09

eipi10


To elaborate on the answer by @eipi10, and to answer a question in the comments by @Maarten Punt, the urlcolor is specifying the color for URL links referenced in the doc. However you might have links to other sections in your document, specified by linkcolor. So you can specify either:

--- title: "R Notebook" output:   pdf_document: default urlcolor: blue linkcolor: red ---  ## test links vs urls  * see [the relevant section](#test)    [link](http://www.rstudio.com)   ```{r cars} summary(cars) ```  \newpage  ## Including Plots{#test}  You can also embed plots, for example:  ```{r pressure, echo=FALSE} plot(pressure) ``` 

enter image description here

The red is a link within the document, whereas the blue is a URL link.

like image 45
Dylan_Gomes Avatar answered Sep 29 '22 14:09

Dylan_Gomes