object2script: Display the Source Code Corresponding to an Object

object2scriptR Documentation

Display the Source Code Corresponding to an Object

Description

Display the source code corresponding to an object.

Usage

object2script(object, ...)

## S3 method for class 'numeric'
object2script(object, digits = NULL, print = TRUE, final.space = "\n", ...)

## S3 method for class 'matrix'
object2script(object, digits = NULL, print = TRUE, final.space = "\n", ...)

## S3 method for class 'data.frame'
object2script(object, digits = NULL, print = TRUE, final.space = "\n", ...)

## S3 method for class 'data.table'
object2script(object, digits = NULL, print = TRUE, final.space = "\n", ...)

## S3 method for class 'list'
object2script(object, digits = NULL, print = TRUE, ...)

Arguments

object

a vector, matrix, data.frame, data.table, or a list of these elements.

...

for compatibility with the generic function.

digits

[interger,>0] indicating the number of decimal places to be used. Passed to round.

print

[logical] should the result be displayed.

final.space

[character] Character string to be added at the end. For internal use.

Examples

## vector
vec <- 1:10
object2script(vec)
object2script(setNames(vec, 1:10))

## matrix
M <- matrix(rnorm(16), 4, 4)
object2script(M)

colnames(M) <- c("a","b","c","d")
object2script(M)

rownames(M) <- c("a","b","c","d")
object2script(M)

## data.frame
df <- data.frame(matrix(rnorm(16), 4, 4),"a")
object2script(df, digits = 5)

## data.table
dt <- data.table(matrix(rnorm(16), 4, 4),"a")
object2script(dt, digits = 5)

## list
l <- list(vec, dt = dt, df = df)
object2script(l)


bozenne/butils documentation built on Oct. 14, 2023, 6:19 a.m.