运行knitr时需要Rmd的文件名 [英] Need the filename of the Rmd when knitr runs

查看:92
本文介绍了运行knitr时需要Rmd的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我询问在knitr运行时是否将r变量设置为Rmd文件的名称.

Recently I asked about having an r variable set to the name of an Rmd file when knitr runs.

何时需要Rnw的文件名knitr在rStudio中运行

knitr:::.knitEnv$input.dir
knitr:::knit_concord$get("infile")

是否存在类似的knitr :::对象作为Rmd文件的名称?

Is there a similar knitr::: object for the name of an Rmd file?

推荐答案

您可以在parent.frames中进行搜索,直到找到引用函数knitr的主体所在位置的帧(因此参数已定义.

You can search through the parent.frames until you find the frame referring to where the body of the function knitr is being evaluated (and thus the input argument is defined.

get(env = parent.frame(n = 8), 'input')

为我工作.

请注意,我没有测试如果input不是文件名.....

Note that I have not tested what happens if input is not a file name.....

这篇关于运行knitr时需要Rmd的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆