From: Ben Pfaff Date: Mon, 2 Sep 2019 06:37:19 +0000 (+0000) Subject: AUTORECODE: Properly handle variable labels. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6415bd1b04855d04669b8582b0082e035658066a;p=pspp AUTORECODE: Properly handle variable labels. --- diff --git a/doc/transformation.texi b/doc/transformation.texi index 01d26621d4..9da42937ea 100644 --- a/doc/transformation.texi +++ b/doc/transformation.texi @@ -271,6 +271,8 @@ If a source value has a value label, then that value label is retained for the new value in the target variable. Otherwise, the source value itself becomes each new value's label. +Variable labels are copied from the source to target variables. + @subcmd{PRINT} is currently ignored. The @subcmd{GROUP} subcommand is relevant only if more than one variable is to be diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index e0b5773909..de7848202f 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -66,6 +66,7 @@ struct arc_spec int src_idx; /* Case index of source variable. */ struct variable *dst; /* Target variable. */ struct missing_values mv; /* Missing values of source variable. */ + char *label; /* Variable label of source variable. */ struct rec_items *items; }; @@ -240,6 +241,9 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) spec->width = var_get_width (src_vars[i]); spec->src_idx = var_get_case_index (src_vars[i]); + const char *label = var_get_label (src_vars[i]); + spec->label = label ? xstrdup (label) : NULL; + if (group && i > 0) spec->items = arc->specs[0].items; else @@ -329,6 +333,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds) /* Create destination variable. */ spec->dst = dict_create_var_assert (dict, dst_names[i], 0); + var_set_label (spec->dst, spec->label); /* Create array of pointers to items. */ n_items = hmap_count (&spec->items->ht); @@ -430,6 +435,7 @@ arc_free (struct autorecode_pgm *arc) hmap_delete (&spec->items->ht, &item->hmap_node); free (item); } + free (spec->label); mv_destroy (&spec->mv); } diff --git a/tests/language/stats/autorecode.at b/tests/language/stats/autorecode.at index 0397e78e4a..97ad28e1c7 100644 --- a/tests/language/stats/autorecode.at +++ b/tests/language/stats/autorecode.at @@ -131,6 +131,7 @@ thingummies 6 oojimiflips 7 end data. +variable labels s 'tracking my stuff'. value labels /s 'thingummies' 'Funny sticky things'. autorecode s into new. @@ -153,11 +154,11 @@ oojimiflips,7.00,2.00 Table: Variables Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values -new,3,,Scale,Input,8,Right,F8.2,F8.2, +new,3,tracking my stuff,Scale,Input,8,Right,F8.2,F8.2, Table: Value Labels Variable Value,,Label -new,1.00,oojars +tracking my stuff,1.00,oojars ,2.00,oojimiflips ,3.00,Funny sticky things ,4.00,widgets