csvkit.schema: Convert a parsed dictionary file to a csvkit schema file

Description Usage Arguments Details Author(s) References Examples

Description

After parsing a .dct dictionary file with the dct.parser function, it may be useful to convert that file to a schema that can be used by csvkit, a useufl Pyton tool for working with csv files. In particular, this creates a schema that allows you to convert a fixed width format file to a csv file.

Usage

1
  csvkit.schema(x, columns.to.match = NULL)

Arguments

x

Your input data.frame. Must include at least the following information in separate columns: the variable names, the starting position of the variable, and the length of the variable in the fixed width file.

columns.to.match

By default, if the input file is the output of dct.parser, the values for this argument do not need to be specified. If you are using your own data.frame, specify which columns contain the (1) variable name, (2) the starting position, and (3) the width of the variable.

Details

This function will write a csv file to your current working directory. It takes the name of the original parsed dictionary file appended with .csv by default (which is stored as an attribute of the data.frame created during the dictionary parsing step). If that attribute is not present, it prompts the user for a file name, which should be provided not quoted.

Author(s)

Ananda Mahto

References

csvkit's in2csv documentation: https://csvkit.readthedocs.org/en/latest/scripts/in2csv.html

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Read an example dictionary file
data(sampleDctData)
## Write the data to a dictionary file
currentdir <- getwd()
setwd(tempdir())
writeLines(sipp84fp_dct, "sipp84fp.dct")
sipp84_R_dict <- dct.parser("sipp84fp.dct")
list.files(pattern=".dat|.dct|.csv")
csvkit.schema(sipp84_R_dict)
list.files(pattern=".dat|.dct|.csv")
setwd(currentdir)

mrdwab/StataDCTutils documentation built on May 23, 2019, 7:15 a.m.