R Markdown-Rmd文件外部的超链接 [英] R Markdown - Hyperlink outside Rmd file
问题描述
我想知道如何为Rmd文件外部的R markdown定义超链接.在Rmd文件中定义超链接就像键入[hyperlink lable](实际链接)一样容易;但是,如果在Rmd文件上,我正在调用其他一些生成文件地址的R文件(例如,一个函数),是否可以将这些信息传回Rmd文件,从而在其中生成超链接?>
请参阅下面的示例以获取更多说明:
内部Rmd文件:
myFun(有一些输入)
在myFun内部:
myFun<-函数(带有某些输入)一些计算...return("[单击此处](C:/myFile.docx)")
生成的html页面上的输出为:
[1]"[单击此处](C:/myFile.docx)"
这不是超链接!
如问题中所述,假设'myFun'函数的输出是超链接字符串,这是最适合我的方法:
在myFun内部:
myFun<-function()...生成CSV文件的一些计算...return("C:/myFile.csv")
内部Rmd文件:
```{r,echo = FALSE}myHyperlink<-myFun()超链接存在=!is.null(myHyperlink)``````{r,eval = hyperlink_exists,results ="asis",echo = FALSE}cat(paste0(文件已保存","[",这里",](",myHyperlink,)","\ n"))```
I am wondering how we can define a hyperlink for R markdown outside Rmd file. Defining a hyperlink inside Rmd file is as easy as typing [hyperlink lable](actual link); but, if on the Rmd file, I am calling some other r-file (e.g., a function) that generates an address to a file, is there a way to transfer this information back to Rmd file to generate a hyperlink there?
Please see example below for more clarification:
Inside Rmd file:
myFun( with some input)
Inside myFun:
myFun <- function( with some input)
some calculations...
return("[click here](C:/myFile.docx)")
The output on the generated html page is:
[1] "[click here] (C:/myFile.docx)"
Which is not a hyperlink!
As mentioned in the question, assuming the output of 'myFun' function is the hyperlink string, here is what worked best for me:
Inside myFun:
myFun <- function()
...some calculations to generate a csv file...
return("C:/myFile.csv")
Inside Rmd file:
```{r, echo=FALSE}
myHyperlink <- myFun()
hyperlink_exists = !is.null(myHyperlink)
```
```{r, eval=hyperlink_exists, results="asis", echo=FALSE}
cat(paste0("The file is saved ","[", "Here", "](", myHyperlink, ")","\n"))
```
这篇关于R Markdown-Rmd文件外部的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!