开发者

R, individual ?argument function that leads to own online help

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, simil开发者_开发知识库ar 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


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)


'#' 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.


You can change what ?foo does by reassigning it:

> assign("?",function(x){cat("HALP!\n")})
> ?foo
HALP!

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.


You could define a binary operator, then pass anything in to the first argument, e.g.,

"%w%" <- function(x, y) w(y)
1%w%argument

It's 4 keys rather than 1, but that's about as close as you can get without major reworking of R.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜