Metadata for a Data Frame
contents.Rdcontents is a generic method for which contents.data.frame
is currently the only method. contents.data.frame 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. print.contents.data.frame
will print the results, with options for sorting the variables.
html.contents.data.frame 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.
If options(prType='html') is in effect, calling print on
an object that is the contents of a data frame will result in
rendering the HTML version. If run from the console a browser window
will open.
Usage
contents(object, ...)
# S3 method for class 'data.frame'
contents(object, sortlevels=FALSE, id=NULL,
range=NULL, values=NULL, ...)
# S3 method for class 'contents.data.frame'
print(x,
sort=c('none','names','labels','NAs'), prlevels=TRUE, maxlevels=Inf,
number=FALSE, ...)
# S3 method for class 'contents.data.frame'
html(object,
sort=c('none','names','labels','NAs'), prlevels=TRUE, maxlevels=Inf,
levelType=c('list','table'),
number=FALSE, nshow=TRUE, ...)
# S3 method for class 'list'
contents(object, dslabels, ...)
# S3 method for class 'contents.list'
print(x,
sort=c('none','names','labels','NAs','vars'), ...)Arguments
- object
a data frame. For
htmlis an object created bycontents. Forcontents.listis a list of data frames.- sortlevels
set to
TRUEto 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 thehtmlmethod as having identical levels if sorted.- id
an optional subject ID variable name that if present in
objectwill cause the number of unique IDs to be printed in the contents header- range
an optional variable name that if present in
objectwill cause its range to be printed in the contents header- values
an optional variable name that if present in
objectwill cause its unique values to be printed in the contents header- x
an object created by
contents- sort
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. Forcontents.list,sortmay also be the value"vars"to cause sorting by the number of variables in the dataset.- prlevels
set to
FALSEto not print all levels offactorvariables- maxlevels
maximum number of levels to print for a
factorvariable- number
set to
TRUEto have theprintandlatexmethods number the variables by their order in the data frame- nshow
set to
FALSEto suppress outputting number of observations and number ofNAs; useful when these counts would unblind information to blinded reviewers- levelType
By default, bullet lists of category levels are constructed in html. Set
levelType='table'to put levels in html table format.- ...
arguments passed from
htmltoformat.df, unused otherwise- dslabels
named vector of SAS dataset labels, created for example by
sasdsLabels
Value
an object of class "contents.data.frame" or
"contents.list". For the html method is an html
character vector object.
Author
Frank Harrell
Vanderbilt University
fh@fharrell.com
Examples
set.seed(1)
dfr <- data.frame(x=rnorm(400),y=sample(c('male','female'),400,TRUE),
stringsAsFactors=TRUE)
contents(dfr)
#>
#> Data frame:dfr 400 observations and 2 variables Maximum # NAs:0
#>
#>
#> Levels Storage
#> x double
#> y 2 integer
#>
#> +--------+-----------+
#> |Variable|Levels |
#> +--------+-----------+
#> | y |female,male|
#> +--------+-----------+
dfr <- upData(dfr, labels=c(x='Label for x', y='Label for y'))
#> Input object size: 6160 bytes; 2 variables 400 observations
#> New object size: 6992 bytes; 2 variables 400 observations
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)
#>
#> Data frame:dfr 400 observations and 2 variables Maximum # NAs:0
#>
#>
#> Labels Levels Class Storage
#> x Label for x numeric double
#> y Label for y 2 integer
#> +--------+------------------------------------------------------------------+
#> |Variable| Long Label |
#> +--------+------------------------------------------------------------------+
#> |x |A very long label for x that can continue onto multiple long lines|
#> | | of text|
#> +--------+------------------------------------------------------------------+
if (FALSE) { # \dontrun{
html(k)
html(contents(dfr)) # same result
latex(k$contents) # latex.default just the main information
} # }