Skip to contents

Creates a Table Schema for a data frame, listing all column names and types as field names and (converted) types.

Usage

create_schema(data)

Arguments

data

A data frame.

Value

List describing a Table Schema.

Table schema properties

The Table Schema will be created from the data frame columns:

  • name: contains the column name.

  • title: not set.

  • description: not set.

  • type: contains the converted column type (see further).

  • format: not set and can thus be considered default. This is also the case for dates, times and datetimes, since readr::write_csv() used by write_package() will format those to ISO8601 which is considered the default. Datetimes in local or non-UTC timezones will be converted to UTC before writing.

  • constraints: not set, except for factors (see further).

  • missingValues: not set. write_package() will use the default "" for missing values.

  • primaryKey: not set.

  • foreignKeys: not set.

Field types

The column type will determine the field type, as follows:

See also

Other create functions: create_package()

Examples

# Create a data frame
df <- data.frame(
  id = c(as.integer(1), as.integer(2)),
  timestamp = c(
    as.POSIXct("2020-03-01 12:00:00", tz = "EET"),
    as.POSIXct("2020-03-01 18:45:00", tz = "EET")
  ),
  life_stage = factor(c("adult", "adult"), levels = c("adult", "juvenile"))
)

# Create a Table Schema from the data frame
schema <- create_schema(df)
str(schema)
#> List of 1
#>  $ fields:List of 3
#>   ..$ :List of 2
#>   .. ..$ name: chr "id"
#>   .. ..$ type: chr "integer"
#>   ..$ :List of 2
#>   .. ..$ name: chr "timestamp"
#>   .. ..$ type: chr "datetime"
#>   ..$ :List of 3
#>   .. ..$ name       : chr "life_stage"
#>   .. ..$ type       : chr "string"
#>   .. ..$ constraints:List of 1
#>   .. .. ..$ enum: chr [1:2] "adult" "juvenile"