I have documentation for functions and datasets in a project folder. In a documentation folder, I have .Rd files for all the datasets. I'd like the user to be able to call a custom help function and launch the .Rd file in the viewer as is done automatically when the file is compiled from the file editor. Is it possible to do this?
Asked
Active
Viewed 1,749 times
2
-
Sorry for being dim, but what is the `.Rd` file viewer? Are you talking about the pane which shows the environment variables? – r2evans Apr 09 '18 at 20:19
-
@r2evans I'm the one lacking vocabulary. If you load an .Rd file into the Rstudio edit, it can be compiled using ctl+shift+K and a version is loaded into what I think is the HTML viewer. – AdamO Apr 09 '18 at 20:20
-
Okay, I think I follow (I was going down the wrong rabbit hole). Is the code offered as a package, or just a bunch of `.Rd` files? – r2evans Apr 09 '18 at 20:22
-
@r2evans just a bunch of .Rd files – AdamO Apr 09 '18 at 20:33
-
I do not believe there is a way to call `help` with a specific path of a file; `help` looks within installed packages. If you can, provide a [R package](http://r-pkgs.had.co.nz/), even if all it has are datasets and `.Rd` files. If you want to provide custom functions that open the help file in the preferred "help file viewer" for each user (and not do a package), I suggest you take a look at `utils:::print.help_files_with_topic` and mimic it best you can. (Not an answer, just a pointer in the right direction.) – r2evans Apr 09 '18 at 20:47
1 Answers
5
I don't quite understand why you want to do this, but it's possible. What you should do is just put your datasets into a package, document them there, and then users get easy access to them.
But if you really want to avoid that for some reason, here's how:
library(magrittr)
library(htmltools)
library(tools)
f <- "some.Rd" # Set a filename for an Rd file here
f %>%
parse_Rd %>%
(function(x) capture.output(Rd2HTML(x))) %>%
HTML %>%
browsable

user2554330
- 37,248
- 4
- 43
- 90
-
1I had never looked for those funcs in `tools`, good to learn something. – r2evans Apr 10 '18 at 04:27
-
Thanks for `Rd2HTML` and `tools`. I now do `tools::Rd2txt("man/some.Rd")`. – chan1142 Dec 29 '21 at 04:22
-
So its `browsable(HTML(capture.output(Rd2HTML("some.Rd"))))` without `magrittr`. Great! Thanks! – chan1142 Dec 30 '21 at 13:26