Skip to content

read_table

Syntax

read_table(table_name, filename, key_col, val_col)

Parameters

table_name
The table to update
filename
The name of comma-separated file. The file-name may include the path to the file.
key_col
The index of the column containing keys
key_val

The index of the column containing values

Description

Updates a provided table with a series of key-value pairs from the specified filename.

The file must be a comma-separated-value file that contains the indicated columns. The assignments of key-value pairs is sequential, so that if a key occurs more than once in the file, the final value will be associated with that key in the table.

Empty lines in the file are ignored.

Lines with a non-numeric value in the first column are ignored.

The value associated with any key that appears in the key_col is replaced by the value in the file. Other keys are not affected.

Note

This action does not change any key-value pair in the table if the key does not occur in the file. This means that this action can only increase the number of key-value pairs in the table.

An error occurs if the file is not found, or if the column indices do not exist.

Examples

# Populates the county_pop_size table using tabulated values from county-pops.csv 
read_table(county_pop_size, county-pops.csv, 0, 1)

See Also