Console print function R function index

I want to print the documentation for the R package on the console. Performance

utils:::.getHelpFile(help("print")) 

works fine but when i try

 utils:::.getHelpFile(help(package="MASS")) 

I get an error message:

 Error in dirname(file) : a character vector argument expected 

So my question is: how can I print the documentation for package R (ie help(package="package_name") ) on the console? Thanks in advance.

+7
r
source share
2 answers

help(package = "MASS") takes you to the INDEX file for the MASS package, which opens in a browser window (depending on your settings). To read this file in the console, we can use system.file() to get the file path, then readLines() to read it as a character vector.

 ## get the complete file path for the index file of the MASS package f <- system.file("INDEX", package = "MASS") ## read it readLines(f) # [1] "Functions:" # [2] "=========" # [3] "" # [4] "Null Null Spaces of Matrices" # [5] "addterm Try All One-Term Additions to a Model" # [6] "anova.negbin Likelihood Ratio Tests for Negative Binomial GLMs" # ... # ... 

Or we can wrap it in cat() to get a cleaner version

 cat(readLines(f), sep = "\n") # Functions: # ========= # # Null Null Spaces of Matrices # addterm Try All One-Term Additions to a Model # anova.negbin Likelihood Ratio Tests for Negative Binomial GLMs # ... # ... 

Alternatively, you can get the same result with

 readLines(file.path(find.package("MASS"), "INDEX")) 

Finally, if you are interested, links to the package description and news that appear at the top of the html browser can be obtained using

 packageDescription("MASS") news(package = "MASS") 
+7
source share

utils:::.getHelpFile(help(package="MASS")) does not work because help(pacakge="MASS") returns an object of the packageInfo class and not an object of the help_files_with_topic class (which is the full path to the file with some other attributes).

Here is the simplest thing I can think of:

 cat(paste(format(help(package="MASS", help_type="text")), collapse="\n"),"\n") 

Basically, you format output from help(package="MASS") . Then paste , which result in a single character string, is collapsed together with newline characters. Then call cat on this result.

+3
source share

All Articles