Next: , Previous: , Up: Dictionaries   [Contents][Index]

2.6.5 Renaming Variables

These functions change the names of variables within a dictionary. The var_set_name function (see var_set_name) cannot be applied directly to a variable that is in a dictionary, because struct dictionary contains an index by name that var_set_name would not update. The following functions take care to update the index as well. They also ensure that variable renaming does not cause a dictionary to contain a duplicate variable name.

Function: void dict_rename_var (struct dictionary *dict, struct variable *var, const char *new_name)

Changes the name of var, which must be in dict, to new_name. A variable named new_name must not already be in dict, unless new_name is the same as var’s current name.

Function: bool dict_rename_vars (struct dictionary *dicT, struct variable **vars, char **new_names, size_t count, char **err_name)

Renames each of the count variables in vars to the name in the corresponding position of new_names. If the renaming would result in a duplicate variable name, returns false and stores one of the names that would be be duplicated into *err_name, if err_name is non-null. Otherwise, the renaming is successful, and true is returned.