2
function preprocess () { ?>
4
<? if (getRK_val ("do_locale_conversion")) { ?>
6
# helper function to convert all strings to the current encoding
7
iconv.recursive <- function (x, from) {
8
attribs <- attributes (x);
9
if (is.character (x)) {
10
x <- iconv (x, from=from, to="", sub="")
11
} else if (is.list (x)) {
12
x <- lapply (x, function (sub) iconv.recursive (sub, from))
14
# convert factor levels and all other attributes
15
attributes (x) <- lapply (attribs, function (sub) iconv.recursive (sub, from))
21
function calculate () {
22
if (getRK_val ("data_frame")) {
24
$data_frame_opt = ", to.data.frame=TRUE";
27
if (getRK_val ("use_labels")) {
28
$labels_opt .= ", max.value.labels=" . getRK_val ("labels_limit");
29
if (getRK_val ("trim_labels")) $labels_opt .= ", trim.factor.names=TRUE";
31
$labels_opt = ", use.value.labels=FALSE";
34
$object = getRK_val ("saveto");
36
data <- read.spss ("<? getRK ("file"); ?>"<? echo ($data_frame_opt); echo ($labels_opt); ?>)
37
<? if (getRK_val ("do_locale_conversion")) {
38
$from_locale = getRK_val ("encoding");
39
if ($from_locale == "other") {
40
$from_locale = getRK_val ("user_encoding");
43
# convert all strings to the current encoding
44
data <- iconv.recursive (data, from="<? echo ($from_locale); ?>")
46
if (getRK_val ("convert_var_labels")) { ?>
48
# set variable labels for use in RKWard
49
labels <- attr (data, "variable.labels");
50
if (!is.null (labels)) {
51
for (i in 1:length (labels)) {
52
col <- make.names (names (labels[i]))
54
rk.set.label (data[[col]], labels[i])
60
<? echo ($object); ?> <<- data # assign to globalenv()
62
if (getRK_val ("doedit") && $data_frame) { ?>
63
rk.edit (<? echo ($object); ?>)
67
function printout () {