Crunch variables are created by posting a VariableDefinition to the Crunch server. The VariableDefinition contains the information the server requires to calculate the variable. This can information can either be in the form of the actual data which you would like to include in the variable, or a derivation which tells the server how to derive the new variable from existing ones. This function converts an R vector or set of attributes into a variable definition which can be posted to the server.

VariableDefinition(data, ...)

VarDef(data, ...)

Arguments

data

an R vector of data to convert to the Crunch payload format. See toVariable for how R data types are converted. This function can also be used to construct a VariableDefinition directly by passing attributes to .... This is only recommended for advanced users who are familiar with the Crunch API.

...

additional attributes to be included in the VariableDefinition

Value

a VariableDefinition object, ready to POST to Crunch.

See also

toVariable

Examples

VariableDefinition(rnorm(5),
    name = "Some numbers",
    description = "Generated pseudorandomly from the normal distribution"
)
#> $values
#> [1] -0.314909052  0.006766418  0.097932173  1.162183571 -0.866445881
#> 
#> $type
#> [1] "numeric"
#> 
#> $name
#> [1] "Some numbers"
#> 
#> $description
#> [1] "Generated pseudorandomly from the normal distribution"
#> 
#> attr(,"class")
#> [1] "VariableDefinition"
VarDef(
    name = "Integers", values = 1:5, type = "numeric",
    description = "When creating variable definitions with 'values', you must
    specify 'type', and categorical variables will require 'categories'."
)
#> $name
#> [1] "Integers"
#> 
#> $values
#> [1] 1 2 3 4 5
#> 
#> $type
#> [1] "numeric"
#> 
#> $description
#> [1] "When creating variable definitions with 'values', you must\n    specify 'type', and categorical variables will require 'categories'."
#> 
#> attr(,"class")
#> [1] "VariableDefinition"