让对象处于其名称很重要的情况下
我有一个函数列表,我想为其制作文档。我的问题不是如何做到这一点,而是它提供了一个我好奇的事情的方便示例。
prompt
将函数和字符串作为参数,并将该函数的帮助文件写入字符串路径表示的文件中。在循环文件时,使用 prompt(f,filename=...)
不起作用,因为 f 是字符类型。我尝试了 get(f)
,它很好地提取了该函数,但没有给出足够的提示信息来使用(见下文)。那么如何强制字符元素返回整个对象而不仅仅是它命名的函数呢?
files <- c("current.market","current.portfolio.bond","fund","genAccount","genHistory.market","history.market","maRketSim.version","summary.vasicek.discrete","vasicek.discrete")
for(f in files) {
prompt( get(f), filename=paste("c:/myproject/man/",f,".Rd",sep="") )
}
Error in prompt.default(get(f), filename = paste("F:/Documents/R-projects/maRketSim/man/", :
cannot determine a usable name
I have a list of functions that I'd like to make documentation for. My question is not about how to do this, but it provides a convenient example of something I'm curious about.
prompt
takes a function and a character string as arguments, and writes a help file on that function to the file represented by the character string path. In looping over the files, using prompt(f,filename=...)
doesn't work since f is of type character. I tried get(f)
, which pulls the function out just fine, but doesn't give prompt enough information to work with (see below). So how do I force a character element to return the whole object not just the function that it names?
files <- c("current.market","current.portfolio.bond","fund","genAccount","genHistory.market","history.market","maRketSim.version","summary.vasicek.discrete","vasicek.discrete")
for(f in files) {
prompt( get(f), filename=paste("c:/myproject/man/",f,".Rd",sep="") )
}
Error in prompt.default(get(f), filename = paste("F:/Documents/R-projects/maRketSim/man/", :
cannot determine a usable name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
?prompt
告诉我们,所以我认为
prompt()
已经做了你想要的事情:它确实产生了相关的 Rd 文件:
我应该添加,
get(" foo")
确实返回实际函数,这只是prompt()
的编码方式,它不能与返回的匿名函数一起使用通过get()
。?prompt
tells us thatSo I think
prompt()
already does what you want:Which does produce the relevant Rd file:
I should add, that
get("foo")
does return the actual function, it is just the way thatprompt()
is coded that it can't work with an anonymous function as returned byget()
.