mandate: The mandate() function enforces a data.frame to follow a...

Description Usage Arguments Details Value See Also Examples

Description

The mandate() function converts each column of the supplied data.frame to the type listed in the supplied schema. If the schema specs that data.frame column j should be numeric, then 'as.numeric(df[,j])' will be the result.

Usage

1
mandate(df, schema)

Arguments

df

a data.frame whose column types and names will be mandated against a schema

schema

a nested list containing schematics used to mandate the data.frame df argument

Details

the schema argument should be the output of scheme.

Value

an output data.frame similar to the input 'df' but the column types of 'df' may have been converted according to 'schema'

See Also

scheme

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
iris2=cbind(iris,Species_chr=as.character(iris$Species))
save_df_schema(x=iris2,outdir='~/projects/datzen/tests/')
schema_in = jsonlite::read_json('~/projects/datzen/tests/iris2_schema.json',simplifyVector = TRUE)

library(dplyr)

mandate(iris2,schema = schema_in) %>% str

iris3 = iris2 %>% mutate_all(.funs=funs(as.character))
iris3 %>% str

mandate(iris3,schema = schema_in) %>% str

mikejacktzen/datzen documentation built on June 14, 2019, 5:23 p.m.