pvar: Prints the name and value of one or more objects

Description Usage Arguments Details Value Author(s) Examples

View source: R/pvar.R

Description

A convenience function for writing the names and values of objects to the session window (and/or to another object). Especially useful to keep track of variables within loops.

Usage

1
pvar(..., digits = NULL, abbrev = NULL, sep = ";", verbose = TRUE)

Arguments

...

Objects whose names and values are to be printed, separated by commas. Can also be a simple list.

digits

Number of digits to display for numeric objects. Defaults to NULL, which corresponds to no restriction on the number of digits. This is passed to the digits argument of round.

abbrev

Number of characters to display for character objects. Defaults to NULL, which corresonds to no restriction on the number of characters.

sep

Character string that separates the objects that are printed

verbose

=TRUE writes the value of the object(s) to the session window

Details

Input objects can be numeric, character, and/or logical. They can also be atomic or vectors. It will accept data frames and matrices without error, but the results won't be easily readable.

Value

Invisibly returns a character string containing the names of the objects and their values

Author(s)

Landon Sego

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
x <- 10
y <- 20.728923
z <- "This.long.string"

pvar(x, y, z)
pvar(x, y, z, digits = 2)
pvar(x, y, z, abbrev = 4)
pvar(x, y, z, digits = 2, abbrev = 4)
pvar(x, y, z, sep = ",")

# values can be vectors too
x <- 10:12
y <- c("This","That")
v2 <- pvar(x, y, verbose = FALSE)
v2

# Or a simple list
pvar(list(x = 1:2, y = "this", z = TRUE))

# Can be useful for keeping track of iterations in loops
for (i in 1:2) {
  for (j in letters[1:2]) {
    for (k in c("this","that")) {
      pvar(i, j, k)
    }
  }
}

Smisc documentation built on May 2, 2019, 2:46 a.m.