[rkward] /: Add previews to SPSS and Stata import plugins.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Mon Jan 11 15:13:57 UTC 2016
Git commit 5da2231653c04d68069aa64654683485f662cb19 by Thomas Friedrichsmeier.
Committed on 11/01/2016 at 15:13.
Pushed by tfry into branch 'master'.
Add previews to SPSS and Stata import plugins.
M +1 -0 ChangeLog
M +16 -4 rkward/plugins/00saveload/import/import_spss.js
M +1 -0 rkward/plugins/00saveload/import/import_spss.rkh
M +1 -0 rkward/plugins/00saveload/import/import_spss.xml
M +15 -3 rkward/plugins/00saveload/import/import_stata.js
M +1 -0 rkward/plugins/00saveload/import/import_stata.rkh
M +1 -0 rkward/plugins/00saveload/import/import_stata.xml
http://commits.kde.org/rkward/5da2231653c04d68069aa64654683485f662cb19
diff --git a/ChangeLog b/ChangeLog
index edf8afb..9bcc43f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
- Fixed: Numerical (display) precision setting was not honored in data editor
- Fix several window activation quirks in "Focus follows mouse" mode
- File selectors in "Import XYZ" plugins now filter for standard file extensions, by default
+- Add previews for CSV, SPSS, and Stata import plugins
- Allow previews for data, (HTML) output, and custom types of previews
- Allow previews to be docked to the dialog window
- Implicitly save code preview visibility and size (instead of the former explicit settings)
diff --git a/rkward/plugins/00saveload/import/import_spss.js b/rkward/plugins/00saveload/import/import_spss.js
index 2c5b8ae..2d06e05 100644
--- a/rkward/plugins/00saveload/import/import_spss.js
+++ b/rkward/plugins/00saveload/import/import_spss.js
@@ -5,10 +5,18 @@ function preprocess () {
makeEncodingPreprocessCode ();
}
+function preview () {
+ doCalculate (true);
+}
+
function calculate () {
+ doCalculate (false);
+}
+
+function doCalculate (is_preview) {
var data_frame = "";
var data_frame_opt = "";
- if (getValue ("data_frame")) {
+ if (getValue ("data_frame") || is_preview) {
data_frame = true;
data_frame_opt = ", to.data.frame=TRUE";
}
@@ -39,9 +47,13 @@ function calculate () {
echo ('}\n');
}
echo ('\n');
- echo ('.GlobalEnv$' + object + ' <- data '); comment ('assign to globalenv()');
- if (getValue ("doedit") && data_frame) {
- echo ('rk.edit (.GlobalEnv$' + object + ')\n');
+ if (is_preview) {
+ echo ('preview_data <- data[1:min(50,dim(data)[1]),1:min(50,dim(data)[2])]\n');
+ } else {
+ echo ('.GlobalEnv$' + object + ' <- data '); comment ('assign to globalenv()');
+ if (getValue ("doedit") && data_frame) {
+ echo ('rk.edit (.GlobalEnv$' + object + ')\n');
+ }
}
}
diff --git a/rkward/plugins/00saveload/import/import_spss.rkh b/rkward/plugins/00saveload/import/import_spss.rkh
index c654eda..e671540 100644
--- a/rkward/plugins/00saveload/import/import_spss.rkh
+++ b/rkward/plugins/00saveload/import/import_spss.rkh
@@ -22,6 +22,7 @@ Choose the SPSS data file to import. Usually those files have the ending '*.sav'
<setting id="use_labels">Should SPSS variables with value labels be converted to R factors with those levels?</setting>
<setting id="labels_limit">Maximum number of factor levels to use (see <link href="rkward://rhelp/read.spss" />)</setting>
<setting id="trim_labels">Trim trailing white space from labels?</setting>
+ <setting id="preview">Preview imported data. Only the first 50 rows and columns are shown, for performance reasons. Internally, the preview uses a data.frame, even if <label id="data_frame"/> is not checked.</setting>
<insert snippet="encoding_doc"/>
</settings>
<related>
diff --git a/rkward/plugins/00saveload/import/import_spss.xml b/rkward/plugins/00saveload/import/import_spss.xml
index 70a2298..19622e8 100644
--- a/rkward/plugins/00saveload/import/import_spss.xml
+++ b/rkward/plugins/00saveload/import/import_spss.xml
@@ -33,6 +33,7 @@
<spinbox id="labels_limit" type="integer" initial="1000000" min="1" label="Maximum number of labels per object" />
<checkbox id="trim_labels" checked="false" label="Trim white space" value="1" value_unchecked="0"/>
</frame>
+ <preview id="preview" active="true" mode="data"/>
</tab>
<insert snippet="encoding_tab"/>
</tabbook>
diff --git a/rkward/plugins/00saveload/import/import_stata.js b/rkward/plugins/00saveload/import/import_stata.js
index ae85ffe..962de39 100644
--- a/rkward/plugins/00saveload/import/import_stata.js
+++ b/rkward/plugins/00saveload/import/import_stata.js
@@ -5,7 +5,15 @@ function preprocess () {
makeEncodingPreprocessCode ();
}
+function preview () {
+ doCalculate (true);
+}
+
function calculate () {
+ doCalculate (false);
+}
+
+function doCalculate () {
var options = "";
if (getValue ("convert_dates")) {
@@ -48,9 +56,13 @@ function calculate () {
echo (' }\n');
echo ('}\n');
echo ('\n');
- echo ('.GlobalEnv$' + object + ' <- data '); comment ('assign to globalenv()');
- if (getValue ("doedit") ) {
- echo ('rk.edit (.GlobalEnv$' + object + ')\n');
+ if (is_preview) {
+ echo ('preview_data <- data[1:min(50,dim(data)[1]),1:min(50,dim(data)[2])]\n');
+ } else {
+ echo ('.GlobalEnv$' + object + ' <- data '); comment ('assign to globalenv()');
+ if (getValue ("doedit") ) {
+ echo ('rk.edit (.GlobalEnv$' + object + ')\n');
+ }
}
}
diff --git a/rkward/plugins/00saveload/import/import_stata.rkh b/rkward/plugins/00saveload/import/import_stata.rkh
index 287cd53..8f346bf 100644
--- a/rkward/plugins/00saveload/import/import_stata.rkh
+++ b/rkward/plugins/00saveload/import/import_stata.rkh
@@ -21,6 +21,7 @@ Choose the STATA data file to import. Usually those files have the ending '*.dta
<setting id="convert_factors">R uses value labels only for factors. Should Stata variable with value labels be converted to factors?</setting>
<setting id="missing_type">Stata version 8 and above differentiates various different type of missing values. If this option is set, this information is stored in an attribute of the imported data. See <link href="rkward://rhelp/read.dta"/> for details.</setting>
<setting id="convert_underscore">The underscore ('_') is usually not used in R variable names, and may cause problems in some (rare) situations. Should underscore characters be converted to dots ('.')?</setting>
+ <setting id="preview">Preview imported data. Only the first 50 rows and columns are shown, for performance reasons.</setting>
<insert snippet="encoding_doc"/>
</settings>
<related>
diff --git a/rkward/plugins/00saveload/import/import_stata.xml b/rkward/plugins/00saveload/import/import_stata.xml
index a273823..414e987 100644
--- a/rkward/plugins/00saveload/import/import_stata.xml
+++ b/rkward/plugins/00saveload/import/import_stata.xml
@@ -26,6 +26,7 @@
<checkbox id="missing_type" checked="false" label="For version 8 or later, store information about different types of missing data?" value="1" value_unchecked="0"/>
<checkbox id="convert_underscore" checked="false" label="Convert '_' in Stata variable names to '.' in R names" value="1" value_unchecked="0"/>
</frame>
+ <preview id="preview" active="true" mode="data"/>
</tab>
<insert snippet="encoding_tab"/>
</tabbook>
More information about the rkward-tracker
mailing list