6

I have a question about the "roxygen2" package:

I have seen a lot of tutorials that make use of it for package documentation (such as the major "object documentation" page by Hadley Wickham)

So what if I do have R code that is not a package, say an R project? Can you document R Projects with roxygen2 as well?

I was still able to run the package.skeleton(name='RoxygenSkeleton', code_files = "Roxygen.R", force=TRUE) function to create the basic package structure and .Rd files were created. But I would desire a nice output in HTML or PDF...

Skybrush
  • 115
  • 1
  • 1
  • 6
  • Since all you want is to generate HTML files, you could just generate the `*.Rd` files, then use [`tools::Rd2HTML`](https://stat.ethz.ch/R-manual/R-devel/library/tools/html/Rd2HTML.html). It's a bit spartan, but it meets your baseline requirement. – r2evans Aug 17 '16 at 14:41
  • @r2evans “generate the *.Rd files” — how? As close as I can make out, this isn’t possible using roxygen2’s public API alone; see my answer. – Konrad Rudolph Aug 17 '16 at 14:49
  • 1
    I think I tried to accomplish something along the lines of what you're trying to do a few years ago. Never completely finished the task but maybe it's of interest to you? https://github.com/Dasonk/flydoc And at the very least the method used in the `flyhelp` function might help get you there? https://github.com/Dasonk/flydoc/blob/master/R/flyhelp.R With that said the code is four years old at the moment so I don't make any guarantees that any of it still works – Dason Aug 17 '16 at 14:50
  • Since (per your discussion with @hadley) there is no way without a package structure, I thought using `Rd2HTML` would meet the last comment (*"I would desire a nice output in HTML"*), given that the OP has already created a skeleton package structure. – r2evans Aug 17 '16 at 14:53
  • @Dason I think you should write an answer for this. – Konrad Rudolph Aug 17 '16 at 14:54
  • @KonradRudolph Maybe later but I haven't actually looked at that code in four years so I'm fuzzy on the details of what I did and how I got any of it to work. – Dason Aug 17 '16 at 14:55
  • Thanks a lot for your input everyone! I really appreciate it. @r2evans Yes I thought about using this workaround as well. It seems like for every function an own .Rd file is generated... so the documentation might be a bit clustered first, and then you could manually merge all files together. – Skybrush Aug 22 '16 at 07:09
  • @Dason - thanks, I will check out your package. It seems like a nice idea for a package. – Skybrush Aug 22 '16 at 07:12

1 Answers1

5

As explained elsewhere, as of roxygen2 6.0, the following works to parse documented R source files outside packages.

source_env = roxygen2::env_file(sourcefile)
rd_blocks = roxygen2::parse_file(sourcefile, source_env)
help_topics = roxygen2::roclet_process(roxygen2::rd_roclet(), rd_blocks, source_env, dirname(sourcefile))
rd_code = lapply(help_topics, format)
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1
    Thanks Konrad! When using Roxygen with a project I saw that it only generated the "skeleton" (e.g. man-repository with .Rd in it) but did not really properly write out my comments in the respective .Rd files. Possibly that is due to using a "project" not "package". Thanks for showing us the workaround. – Skybrush Aug 22 '16 at 07:03