R,单独的参数函数,可导出自己的在线帮助
我有一个内部 wiki,我创建了一个函数 w(argument),它使用 browserURL(url, browser) 直接打开我的 wiki 上的相应页面。但是,我想用 #argument 代替 w(argument),类似于 ?argument。有人知道 R 中是否可以使用快捷键定义这样的函数
非常感谢您的帮助
BR 马丁
I have an internal wiki and I created a function w(argument), which directly opens the corresponding page on my wiki using browseURL(url, browser). However, instead of w(argument), I'd like to replace it by #argument, similar to ?argument. Does somebody know if such a function definition with a shortkey is possible within R
Thanks a lot for your help
BR
Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不。您正在寻找的是在 R 中定义一个新的一元运算符,但这是不可能的。 (并且
#
是 R 中的注释字符,因此无论如何已经使用了,所以这是行不通的。)这个 post 由 Brian Ripley 回答类似的问题,有更多的解释(不多)
No. What you are looking for is to define a new unary operator in R, and that isn't possible. (And
#
is the comment character in R so is used already anyway, so that wouldn't work.)This post by Brian Ripley, in response to a similarly motivated question, has a bit more explanation (not much)
'#' 在 R 中开始注释,因此永远不会通过解析器。如果您确实希望 #foo 做一些事情而不是什么也不做,您将必须修改核心并重新编译 R。
'#' starts a comment in R, so that will never get passed the parser. You'll have to modify the core and recompile R if you really want #foo to do something other than nothing.
您可以通过重新分配 ?foo 来更改它的功能:
显然,如果 arg 不是您感兴趣的内容,您会使其落入默认帮助系统,但这非常难看。
You can change what ?foo does by reassigning it:
Obviously you'd make it fall through to the default help system if the arg isn't what you are interested in, but this is pretty ugly.
您可以定义一个二元运算符,然后将任何内容传递给第一个参数,例如,
它是 4 个键而不是 1 个,但这大约是您无需对 R 进行重大修改即可获得的最接近的值。
You could define a binary operator, then pass anything in to the first argument, e.g.,
It's 4 keys rather than 1, but that's about as close as you can get without major reworking of R.