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

help by `?`? #110

Closed
kohske opened this Issue Jul 2, 2012 · 12 comments

Comments

Projects
None yet
3 participants
@kohske
Contributor

kohske commented Jul 2, 2012

Is there way to show help page in the package that is loaded via load_all?

e.g.,

> l(ggplot2)
Loading ggplot2
> ?aes
No documentation foraesin specified packages and libraries:
you could try ‘??aes
@hadley

This comment has been minimized.

Member

hadley commented Jul 2, 2012

No - and I don't see an easy way to do this. You can use show_rd to see the documentation for a file in a source package though.

@kohske

This comment has been minimized.

Contributor

kohske commented Jul 2, 2012

Yes, but show_rd is file-name based, while ? is object-name based.
Ok, maybe I will hack ? in future.

@hadley

This comment has been minimized.

Member

hadley commented Jul 2, 2012

It's moderately difficult because you need to build up an index from topic to Rd file by looking at all the Rd files.

@kohske

This comment has been minimized.

Contributor

kohske commented Jul 2, 2012

Yes, but Rd file is well structured so it might not be so difficult.

At the moment, reverse lookup of Rd from function (or object name) is sufficient,
so grep alias *.Rd might be the first step.

@kohske

This comment has been minimized.

Contributor

kohske commented Jul 2, 2012

Of course, tools:::parse_Rd is better.

@kohske

This comment has been minimized.

Contributor

kohske commented Jul 2, 2012

I mean like this:

# when load_all(...)
# it makes index of the package inside `namespace:devtools`
files <- list()
files[["ggplot2"]] <- dir("~/Dropbox/dev/R/ggplot2/man", "\\.Rd$", full = TRUE)

r <- lapply(files[["ggplot2"]], function(x) {
  r <- tools:::parse_Rd(x)
  unlist(r[which(tools:::RdTags(r) == "\\alias")])
})

aliases <- list()
aliases[["ggplot2"]] <- r

# and accessor
devq <- function(p, f) {
  i <- which(sapply(aliases[[p]], function(a) any(f == a)))
  print(files[[p]][i])
  if (length(i) == 1) show_rd(p, basename(files[[p]][i]))
}

# use it
devq("ggplot2", "aes")
@hadley

This comment has been minimized.

Member

hadley commented Jul 2, 2012

Hmmm, the problem is then keeping the index in sync after you roxygenise - although I guess document could also update it. And I think we'd just modify show_rd so it could either accept the name of a topic or a file name.

@kohske

This comment has been minimized.

Contributor

kohske commented Jul 2, 2012

Hmmm, the problem is then keeping the index in sync after you roxygenise - although I guess document could also update it.

indexing takes place every time when load_alled the package, so I think there is no sync problem.

But,

And I think we'd just modify show_rd so it could either accept the name of a topic or a file name.

Agreed. This is more simple. Perhaps looking up the topic is not so heavy, so we don't need index.

@wch

This comment has been minimized.

Member

wch commented Aug 9, 2012

With the #126 pull request, this is closer to working.

In help(), this is how it tries to find the help file:

 paths <- index.search(topic, find.package(package, lib.loc, verbose = verbose))

With the changes in the pull request, find.package now finds the directory of the working version of the package, rather than the installed version. I think it uses the path attribute of the <package:ggplot2> environment.

find.package('ggplot2')
# "/Users/winston/Projects/ggplot2"

# with old version of devtools, this reported:
# "/Users/winston/R-dev/ggplot2"

But utils:::index.search looks for help/aliases.rds or help/AnIndex, and these files don't exist. So the index still has to be created somehow.

@hadley

This comment has been minimized.

Member

hadley commented Aug 9, 2012

Hmmm, I could probably figure out how to create those files with roxygen, and then people would have to put them in .gitignore or similar.

@wch

This comment has been minimized.

Member

wch commented Aug 9, 2012

I think you'd also have to generate the help/ and html/ directories.

Another possible solution is to define a function like dhelp(), which would search the man/ directories of all packages loaded via devtools, and then run show_rd for the requested page. Or maybe it's possible to redefine ? to search devtools-loaded packages, and then if it doesn't find the help page, to call the regular ? function.

@hadley

This comment has been minimized.

Member

hadley commented Aug 14, 2012

I think this will be called dev_help or maybe devhelp

@hadley hadley closed this in 8408264 Aug 20, 2012

@lock lock bot locked and limited conversation to collaborators Sep 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.