read.str
and read_str
read the structure printed
when utils::str.data.frame()
back into a data frame.
read.str(file = clipr::read_clip()) read_str(file = clipr::read_clip())
file | Character. A path to a file, a connection, or literal data (either a single string or a vector of lines). If unspecified, reads from the clipboard. |
---|
A data frame of the class specified in the first line of input.
read.str
and read_str
are roughly inverses of str.data.frame
, except:
read.str
subsets to rows where the str
results contain the complete
data for the observation,
attributes are dropped, and
list and matrix columns are unsupported.
Classes at the top of the str
results are reassigned, so both vanilla
data.frame
s and variants like tbl_df
and data.table
are supported.
Because class is determined by the data, read_str
is merely an alias.
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #> 7 4.6 3.4 1.4 0.3 setosa #> 8 5.0 3.4 1.5 0.2 setosa #> 9 4.4 2.9 1.4 0.2 setosa #> 10 4.9 3.1 1.5 0.1 setosa# Resulting class is determined by input, not read.str vs. read_str read_str(capture.output(str(tibble::as_tibble(iris))))#> # A tibble: 10 x 5 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> * <dbl> <dbl> <dbl> <dbl> <fct> #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #> 7 4.6 3.4 1.4 0.3 setosa #> 8 5 3.4 1.5 0.2 setosa #> 9 4.4 2.9 1.4 0.2 setosa #> 10 4.9 3.1 1.5 0.1 setosa