Skip to contents

Modified version of tools:::.Rd_get_metadata() that keeps whitespace and returns character instead of matrix.

Usage

parseRd(object, tag)

rdTags(object)

Arguments

object

Rd. R documentation, returned from tools::Rd_db().

tag

character(1). Desired metadata type.

These types are supported:

  • title.

  • description.

  • usage.

  • arguments.

  • value.

  • references.

  • seealso.

  • examples.

Functions

  • rdTags(): Modified version of the unexported tools:::RdTags() function.

Note

Updated 2023-09-25.

See also

Examples

db <- tools::Rd_db("base")
head(names(db))
#> [1] "Arithmetic.Rd"   "AsIs.Rd"         "Bessel.Rd"       "CallExternal.Rd"
#> [5] "Colon.Rd"        "Comparison.Rd"  
rd <- db[["nrow.Rd"]]
print(rdTags(rd))
#>  [1] "title"       "name"        "alias"       "alias"       "alias"      
#>  [6] "alias"       "keyword"     "description" "usage"       "arguments"  
#> [11] "value"       "references"  "seealso"     "examples"   
examples <- parseRd(rd, tag = "examples")
print(examples)
#>  [1] "ma <- matrix(1:12, 3, 4)"                                               
#>  [2] "nrow(ma)   # 3"                                                         
#>  [3] "ncol(ma)   # 4"                                                         
#>  [4] ""                                                                       
#>  [5] "ncol(array(1:24, dim = 2:4)) # 3, the second dimension"                 
#>  [6] "NCOL(1:12) # 1"                                                         
#>  [7] "NROW(1:12) # 12, the length() of the vector"                            
#>  [8] ""                                                                       
#>  [9] "## as.matrix() produces 1-column matrices from 0-length vectors,"       
#> [10] "## and so does cbind() :"                                               
#> [11] "dim(as.matrix(numeric())) # 0 1"                                        
#> [12] "dim(    cbind(numeric())) # ditto"                                      
#> [13] "NCOL(numeric()) # 1"                                                    
#> [14] "## However, as.matrix(NULL) fails and cbind(NULL) gives NULL, hence for"
#> [15] "## consistency:"                                                        
#> [16] "NCOL(NULL)      # 0"                                                    
#> [17] "## (This gave 1 in R < 4.4.0.)"