Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print the R help from the function if --help is called #2

Open
jeremystan opened this issue Jun 11, 2017 · 1 comment
Open

Print the R help from the function if --help is called #2

jeremystan opened this issue Jun 11, 2017 · 1 comment

Comments

@jeremystan
Copy link
Owner

Is there some way to get the help for an R function as a string and pass that to argparse? Or alternatively redirect --help flags to just use ?f?

@Dasonk
Copy link

Dasonk commented Jun 12, 2017

I'm not at a computer I can easily test this but if you just want to get the help from a function as text you can use tools::Rd2txt to create a text file from the Rd files in a package. That's basically what happens when your help_type is set to 'text' with a bit of additional magic to use an appropriate pager to display the file. I'm guessing the issue. Although that might be beyond what you care about - I was assuming you'd want more control over what gets printed but if you just want to allow the output to be displayed in the console you could use a similar trick that I use to display help files in html vignettes in my docstring package. If you do this:

console_pager <- function(x, ...){
    input <- readLines(x)
    # Had some issues with _� getting displayed
    # in the output console output which
    # messed up rendering in the created html vignette
    # So remove that before outputting.
    input <- gsub("_�", "", input)
    cat(paste(input,collapse="\n"), "\n")}
options(pager=console_pager)

then having the help file display directly in a console works just fine.

It seems to me that one might want to write their own documentation if using aargh though since you might be doing something that isn't just a direct call to a built in function. My docstring package might be useful to use in conjunction with aargh in those cases. If that sounds like something you think users might want to do and have trouble getting it working I'd be more than happy to help with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants