| Title: | Frictionless Standards |
| Version: | 0.5.2 |
| Description: | A "tabular-data-resource" (https://specs.frictionlessdata.io/tabular-data-resource/) is a simple format to describe a singular tabular data resource such as a CSV file. It includes support both for metadata such as author and title and a schema to describe the data, for example the types of the fields/columns in the data. Create a tabular-data-resource by providing a data.frame and specifying metadata. Write and read tabular-data-resources to and from disk. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Imports: | cli, purrr, vroom, S7 (≥ 0.1.1), tibble, tidyselect, yaml,dplyr, rlang |
| Suggests: | testthat (≥ 3.0.0), withr, fs, knitr, rmarkdown, curl |
| Config/testthat/edition: | 3 |
| Config/testthat/parallel: | true |
| URL: | https://github.com/cole-brokamp/fr,https://cole-brokamp.github.io/fr/ |
| BugReports: | https://github.com/cole-brokamp/fr/issues |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2024-11-07 19:00:24 UTC; cole |
| Author: | Cole Brokamp |
| Maintainer: | Cole Brokamp <cole@colebrokamp.com> |
| Repository: | CRAN |
| Date/Publication: | 2024-11-07 19:10:02 UTC |
About the fr package
Description
fr provides functions and objects to reproducibly create and track changes to metadata alongside code that createsthe data. This prevents a disconnect between data and metadata, but also allows for computing on the metadatato create richer documentation.Thefr package providesfr_tdr,fr_schema, andfr_field objects to provide a representation of theFrictionlessTabular Data Resource standards in R.
Afr_tdr, or frictionless tabular data resource, object encapsulates data and metadata by building on topof the data.frame and has a list of data resource-specific metadata properties (e.g.,name,description).one of which is afr_schema (Frictionless Schema) object. One of these is afr_schema object, which is a list of table-specific metadata properties. One of these is a list offr_field objects, which is a list #' field- (or column-) specific metadata properties (e.g.,name,type,constraints)
Normal usage will only require usingas_fr_tdr() to create afr_tdr object based on a data.frame or tibble.
Author(s)
Maintainer: Cole Brokampcole@colebrokamp.com (ORCID) [copyright holder]
Other contributors:
Tomasz Kalinowski [contributor]
See Also
Useful links:
Report bugs athttps://github.com/cole-brokamp/fr/issues
Coerce afr_tdr object into a data frame
Description
Equivalent toas.data.frame(); directly usingtibble::as_tibble()also works because its input is first coerced withas.data.frame()
Usage
as_data_frame(x, ...)Arguments
x | a |
... | ignored |
Value
a data frame
Examples
as_fr_tdr(mtcars, name = "mtcars") |> as_data_frame()Coercecharacter,factor,numeric,logical, andDatevectors intofr_field objects
Description
The supported classes ofR objects are converted to the corresponding frictionlesstype:
R class | fr type |
character() | string |
factor() | string (withenum(constraints = levels(x))) |
numeric(),integer() | number |
logical() | boolean |
Date | date |
Usage
as_fr_field(x, ...)Arguments
x | a character, factor, numeric, integer, logical, or Date vector |
... | < |
Value
afr_field object
Examples
as_fr_field(1:10, "example_integer") # -> frictionless numberas_fr_field((1:10) * 0.1, "example_double") # -> frictionless numberas_fr_field(letters, "example_character") # -> frictionless stringas_fr_field(factor(letters), "example_factor") # -> frictionless string with enum constraintsas_fr_field(c(TRUE, FALSE, TRUE), "example_logical") # -> frictionless booleanas_fr_field(as.Date(c("2023-04-23", "2004-12-31")), "example_date") # -> frictionless dateCoerce a data frame into afr_tdr object
Description
Coerce a data frame into afr_tdr object
Usage
as_fr_tdr(x, ...)Arguments
x | a data.frame |
... | < |
Details
Use the.template argument to provide a templatefr_tdr object from whichtable-specific (i.e. "name", "version", "title", "homepage", "description")and field-specific metadata will be copied; note that all metadata providedin... will be ignored if this argument is provided
Value
afr_tdr object
Examples
as_fr_tdr(mtcars, name = "mtcars")S7::prop(as_fr_tdr(mtcars, name = "mtcars"), "schema")Coerce afr_tdr object into a list
Description
equivalent toas.list()
Usage
as_list(x, ...)Arguments
x | a |
... | ignored |
Value
a list representing the frictionless metadata descriptor
Examples
as_fr_tdr(mtcars, name = "mtcars") |> as_list()dplyr methods for fr_tdr objects
Description
Some basic dplyr functions are re-implemented here for forfr_tdr objects.The input is converted withas.data.frame() before beingpassed to the dplyr function. The resulting tibble object is converted backinto afr_tdr object, matching table- and field-specific metadata wherepossible by usingas_fr_tdr() and specifying the.template argument.
| dplyr | fr |
mutate() | fr_mutate() |
rename() | fr_rename() |
select() | fr_select() |
filter() | fr_filter() |
summarise() | fr_summarise() |
arrange() | fr_arrange() |
Usage
fr_mutate(x, ...)fr_rename(x, ...)fr_select(x, ...)fr_filter(x, ...)fr_summarize(x, ...)fr_arrange(x, ...)Arguments
x | a |
... | passed to the underlying dplyr function |
Value
afr_tdr object
Examples
read_fr_tdr(fs::path_package("fr", "hamilton_poverty_2020")) |> fr_mutate(next_year = year + 1) |> fr_rename(new_year = next_year) |> fr_select(-new_year) |> fr_filter(fraction_poverty > 0.1) |> fr_summarize(median_poverty_fraction = median(fraction_poverty)) |> fr_arrange(median_poverty_fraction)Test if an object is afr_field object
Description
Test if an object is afr_field object
Usage
is_fr_field(x)Arguments
x | an object to test |
Value
TRUE if object is afr_field object,FALSE otherwise
Examples
is_fr_field(letters)is_fr_field(as_fr_field(letters, "letters"))read a tabular-data-resource into R
Description
read a tabular-data-resource into R
Usage
read_fr_tdr(file)Arguments
file | Either a path to a file, a connection, or literal data (either asingle string or a raw vector). Files ending in Literal data is most useful for examples and tests. To be recognised asliteral data, wrap the input with |
Details
A file path (or url) representing a folderthat contains a "tabular-data-resource.yaml" canbe used infile.
Value
afr_tdr object
Examples
read_fr_tdr(fs::path_package("fr", "hamilton_poverty_2020"))add or update field-specific metadata in a fr_tdr object
Description
add or update field-specific metadata in a fr_tdr object
Usage
update_field(x, field, ...)Arguments
x | a |
field | character name of field in x to update |
... | table schema field descriptors (e.g., |
Value
anfr_tdr object containing the updated field
Examples
my_mtcars <- mtcars |> as_fr_tdr(name = "mtcars") |> update_field("mpg", title = "Miles Per Gallon")S7::prop(my_mtcars, "schema")write a fr_tdr object to disk
Description
Thename property of thefr_tdr object is used to write a frictionless tabular-data-resource to disk. For example, ifname = "my_data", then a folder namedmy_data would be created with (1)my_data.csv and (2)tabular-data-resource.yaml.
Usage
write_fr_tdr(x, dir)Arguments
x | afr_tdr object to write to disk |
dir | path to directory where tabular-data-resource folder will be created |
Value
x (invisibly)