column_attr: Get or set a lazy frame column attribute.

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Get or set a lazy frame column attribute.

Usage

1
2

Arguments

x

A lazy.frame object.

col

A numeric column index.

which

The attribute name to set or get.

value

The new attribute value.

Details

Because lazy frames load data from text files on demand, column attributes set in the usual way are ephemeral–they only affect data frame subsets returned as a result of index operations.

Use the column_attr function to set attributes on a lazy frame column that persist for all extracted subsets.

Value

The attribute value is returned by the get version of the function.

Note

This function is typically used to manually set factor levels for factor-valued columns, for example if stringsAsFactors=TRUE. See below for an example.

Author(s)

B. W. Lewis <blewis@illposed.net>

See Also

lazy.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Note that the 5th column of the 'iris' data set is factor coded.
data(iris)
f = tempfile()
write.table(iris, file=f, sep=",", row.names=FALSE, col.names=TRUE)

x = lazy.frame(f, header=TRUE, stringsAsFactors=TRUE)
# Lazy frames load data on demand from the file, they can't automatically
# code factor levels. Subsets will only include factor level codings
# defined within the subset (probably not what you want!), for example:
x[1:3,5]

# If we know all the levels, however, we can explicitly set them with
# the column_attr function:
column_attr(x,5,"levels") <- levels(iris[,5])

# Now we're OK:
x[1:3,5]

unlink(f)

bwlewis/lazy.frame documentation built on May 13, 2019, 9:06 a.m.