contents: Metadata for a Data Frame

View source: R/describe.s

contentsR Documentation

Metadata for a Data Frame


contents is a generic method for which is currently the only method. creates an object containing the following attributes of the variables from a data frame: names, labels (if any), units (if any), number of factor levels (if any), factor levels, class, storage mode, and number of NAs. will print the results, with options for sorting the variables. creates HTML code for displaying the results. This code has hyperlinks so that if the user clicks on the number of levels the browser jumps to the correct part of a table of factor levels for all the factor variables. If long labels are present ("longlabel" attributes on variables), these are printed at the bottom and the html method links to them through the regular labels. Variables having the same levels in the same order have the levels factored out for brevity.

contents.list prints a directory of datasets when sasxport.get imported more than one SAS dataset.


contents(object, ...)
## S3 method for class 'data.frame'
contents(object, sortlevels=FALSE, id=NULL,
  range=NULL, values=NULL, ...)
## S3 method for class ''
    sort=c('none','names','labels','NAs'), prlevels=TRUE, maxlevels=Inf,
    number=FALSE, ...) 
## S3 method for class ''
           sort=c('none','names','labels','NAs'), prlevels=TRUE, maxlevels=Inf,
           number=FALSE, nshow=TRUE, ...)
## S3 method for class 'list'
contents(object, dslabels, ...)
## S3 method for class 'contents.list'
    sort=c('none','names','labels','NAs','vars'), ...)



a data frame. For html is an object created by contents. For contents.list is a list of data frames.


set to TRUE to sort levels of all factor variables into alphabetic order. This is especially useful when two variables use the same levels but in different orders. They will still be recognized by the html method as having identical levels if sorted.


an optional subject ID variable name that if present in object will cause the number of unique IDs to be printed in the contents header


an optional variable name that if present in object will cause its range to be printed in the contents header


an optional variable name that if present in object will cause its unique values to be printed in the contents header


an object created by contents


Default is to print the variables in their original order in the data frame. Specify one of "names", "labels", or "NAs" to sort the variables by, respectively, alphabetically by names, alphabetically by labels, or by increaseing order of number of missing values. For contents.list, sort may also be the value "vars" to cause sorting by the number of variables in the dataset.


set to FALSE to not print all levels of factor variables


maximum number of levels to print for a factor variable


set to TRUE to have the print and latex methods number the variables by their order in the data frame


set to FALSE to suppress outputting number of observations and number of NAs; useful when these counts would unblind information to blinded reviewers


By default, bullet lists of category levels are constructed in html. Set levelType='table' to put levels in html table format.


arguments passed from html to format.df, unused otherwise


named vector of SAS dataset labels, created for example by sasdsLabels


an object of class "" or "contents.list". For the html method is an html character vector object.


Frank Harrell
Vanderbilt University

See Also

describe, html, upData


dfr <- data.frame(x=rnorm(400),y=sample(c('male','female'),400,TRUE),
dfr <- upData(dfr, labels=c(x='Label for x', y='Label for y'))
attr(dfr$x, 'longlabel') <-
 'A very long label for x that can continue onto multiple long lines of text'

k <- contents(dfr)
print(k, sort='names', prlevels=FALSE)
## Not run: 
html(contents(dfr))            # same result
latex(k$contents)              # latex.default just the main information

## End(Not run)

Hmisc documentation built on April 19, 2022, 9:05 a.m.