Skip to contents

Transforms a single character string containing a dictionary in a textual format into a proper dictionary, that is a named character vector

Usage

as.dict(x)

Arguments

x

A character scalar of the form "variable 1: definition \n variable 2: definition" etc. Each line of this character must contain at most one definition with, on the left the variable name, and on the right its definition. The separation between the variable and its definition must be a colon followed with a single space (i.e. ": "). You can stack definitions within a single line by making use of a semi colon: "var1: def; var2: def". White spaces on the left and right are ignored. You can add commented lines with a "#". Non-empty, non-commented lines that don't have the proper format witll raise an error.

Value

It returns a named character vector.

Details

This function is mostly used in combination with setFixest_dict to set the dictionary to be used in the function etable.

Author

Laurent Berge

Examples


x = "# Main vars
     mpg: Miles per gallon
     hp: Horsepower

     # Categorical variables
     cyl: Number of cylinders; vs: Engine"

as.dict(x)
#>                   mpg                    hp                   cyl 
#>    "Miles per gallon"          "Horsepower" "Number of cylinders" 
#>                    vs 
#>              "Engine"