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

parseRd(object, tag)

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.

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"]] class(Rd)
#> [1] "Rd"
#> Length Class Mode #> [1,] 1 -none- list #> [2,] 1 -none- list #> [3,] 1 -none- list #> [4,] 1 -none- list #> [5,] 1 -none- list #> [6,] 1 -none- list #> [7,] 1 -none- list #> [8,] 20 -none- list #> [9,] 5 -none- list #> [10,] 4 -none- list #> [11,] 10 -none- list #> [12,] 10 -none- list #> [13,] 11 -none- list #> [14,] 16 -none- list
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" #> [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] "## consequently, NCOL(.) gives 1, too :" #> [14] "NCOL(numeric()) # 1 and hence" #> [15] "NCOL(NULL) # 1"