Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

str: Compactly Display the Structure of an Arbitrary R Object

strR Documentation

Compactly Display the Structure of an Arbitrary R Object

Description

Compactly display the internalstructure of anR object, adiagnostic function and an alternative tosummary(and to some extent,dput). Ideally, only one line foreach ‘basic’ structure is displayed. It is especially well suitedto compactly display the (abbreviated) contents of (possibly nested)lists. The idea is to give reasonable output foranyRobject. It callsargs for (non-primitive) function objects.

strOptions() is a convenience function for settingoptions(str = .), see the examples.

Usage

str(object, ...)## S3 method for class 'data.frame'str(object, ...)## Default S3 method:str(object, max.level = NA,    vec.len  = strO$vec.len, digits.d = strO$digits.d,    nchar.max = 128, give.attr = TRUE,    drop.deparse.attr = strO$drop.deparse.attr,    give.head = TRUE, give.length = give.head,    width = getOption("width"), nest.lev = 0,    indent.str = paste(rep.int(" ", max(0, nest.lev + 1)),                       collapse = ".."),    comp.str = "$ ", no.list = FALSE, envir = baseenv(),    strict.width = strO$strict.width,    formatNum = strO$formatNum, list.len = strO$list.len,    deparse.lines = strO$deparse.lines, ...)strOptions(strict.width = "no", digits.d = 3, vec.len = 4,           list.len = 99, deparse.lines = NULL,           drop.deparse.attr = TRUE,           formatNum = function(x, ...)                       format(x, trim = TRUE, drop0trailing = TRUE, ...))

Arguments

object

anyR object about which you want to have someinformation.

max.level

maximal level of nesting which is applied fordisplaying nested structures, e.g., a list containing sub lists.Default NA: Display all nesting levels.

vec.len

numeric (>= 0) indicating how many ‘first few’ elementsare displayed of each vector. The number is multiplied by differentfactors (from .5 to 3) depending on the kind of vector. Defaults tothevec.len component of option"str" (seeoptions) which defaults to 4.

digits.d

number of digits for numerical components (as forprint). Defaults to thedigits.d component ofoption"str" which defaults to 3.

nchar.max

maximal number of characters to show forcharacter strings. Longer strings are truncated, seelongch example below.

give.attr

logical; ifTRUE (default), show attributesas sub structures.

drop.deparse.attr

logical; ifTRUE (default),deparse(control = <S>) will not have"showAttributes" in<S>. Used to be hard coded toFALSE and hence can be set viastrOptions() for backcompatibility.

give.length

logical; ifTRUE (default), indicatelength (as[1:...]).

give.head

logical; ifTRUE (default), give (possiblyabbreviated) mode/class and length (as<type>[1:...]).

width

the page width to be used. The default is the currentlyactiveoptions("width"); note that this has only aweak effect, unlessstrict.width is not"no".

nest.lev

current nesting level in the recursive calls tostr.

indent.str

the indentation string to use.

comp.str

string to be used for separating list components.

no.list

logical; if true, no ‘list of ...’ nor theclass are printed.

envir

the environment to be used forpromise (seedelayedAssign) objects only.

strict.width

string indicating if thewidth argument'sspecification should be followed strictly, one of the valuesc("no", "cut", "wrap"), which can be abbreviated.Defaults to thestrict.width component of option"str"(seeoptions) which defaults to"no" for backcompatibility reasons;"wrap" usesstrwrap(*, width = width) whereas"cut" cutsdirectly towidth. Note that a smallvec.lengthmay be better than settingstrict.width = "wrap".

formatNum

a function such asformat forformatting numeric vectors. It defaults to theformatNumcomponent of option"str", see “Usage” ofstrOptions() above, which is almost back compatible toR<= 2.7.x, however, usingformatC may be slightly better.

list.len

numeric; maximum number of list elements to displaywithin a level.

deparse.lines

numeric orNULL as by default, determining thenlines argument todeparse() whenobject isacall. WhenNULL, thenchar.max andwidth arguments are used to determine a smart default.

...

potential further arguments (required for Method/Genericreasons).

Value

str does not return anything, for efficiency reasons.The obvious side effect is output to the terminal.

Note

See the extensive annotated ‘Examples’ below.

The default method tries to “work always”, but needs to make someassumptions for the case whenobject has aclass butno ownstr() method which isthe typical case: There itrelies on"[" and"[[" subsetting methods tobe compatible withlength(). When this is not the case, orwhenis.list(object) isTRUE, butlength(object)differs fromlength(unclass(object)) it treats it as“irregular” and reports the contents ofunclass(object)as “hidden list”.

Author(s)

Martin Maechlermaechler@stat.math.ethz.ch since 1990.

See Also

ls.str forlisting objects with their structure;summary,args.

Examples

require(stats); require(grDevices); require(graphics)## The following examples show some of 'str' capabilitiesstr(1:12)str(ls)str(args) #- more useful than  args(args) !str(freeny)str(str)str(.Machine, digits.d = 20) # extra digits for identification of binary numbersstr( lsfit(1:9, 1:9))str( lsfit(1:9, 1:9), max.level = 1)str( lsfit(1:9, 1:9), width = 60, strict.width = "cut")str( lsfit(1:9, 1:9), width = 60, strict.width = "wrap")op <- options(); str(op)   # save first;                           # otherwise internal options() is used.need.dev <-  !exists(".Device") || is.null(.Device) || .Device == "null device"{ if(need.dev) postscript()  str(par())  if(need.dev) graphics.off()}ch <- letters[1:12]; is.na(ch) <- 3:5str(ch) # character NA'sstr(list(a = "A", L = as.list(1:100)), list.len = 9)##                                     ------------## " .. [list output truncated] "## Long strings,   'nchar.max'; 'strict.width' :nchar(longch <- paste(rep(letters,100), collapse = ""))str(longch)str(longch, nchar.max = 52)str(longch, strict.width = "wrap")## Multibyte characters in strings (in multibyte locales):oloc <- Sys.getlocale("LC_CTYPE")mbyte.lc <- if(.Platform$OS.type == "windows") "English_United States.28605" else "en_GB.UTF-8"try(Sys.setlocale("LC_CTYPE", mbyte.lc))## Truncation behavior (<-> correct width measurement) for "long" non-ASCII:idx <- c(65313:65338, 65345:65350)fwch <- intToUtf8(idx) # full width character string: each has width 2ch <- strtrim(paste(LETTERS, collapse="._"), 64)(ncc <- c(c.ch = nchar(ch),   w.ch = nchar(ch,   "w"),          c.fw = nchar(fwch), w.fw = nchar(fwch, "w")))stopifnot(unname(ncc) == c(64,64, 32, 64))## nchar.max: 1st line needs an increase of  2  in order to see  1  (in UTF-8!):invisible(lapply(60:66, function(N) str(fwch, nchar.max = N)))invisible(lapply(60:66, function(N) str( ch , nchar.max = N))) # "1 is 1" here## revert locale to previous:Sys.setlocale("LC_CTYPE", oloc)## Settings for narrow transcript :op <- options(width = 60,              str = strOptions(strict.width = "wrap"))str(lsfit(1:9,1:9))str(options())## reset to previous:options(op)str(quote( { A+B; list(C, D) } ))## S4 classes :require(stats4)x <- 0:10; y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)ll <- function(ymax = 15, xh = 6)      -sum(dpois(y, lambda=ymax/(1+x/xh), log=TRUE))fit <- mle(ll)str(fit)

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2025 Movatter.jp