[rkward] /: Fix various quirks in XLConnect based XLS-import plugins, and add automated test.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 14 21:21:01 UTC 2016
Git commit 331411e4245f28a4c30687633d39595c0e9358c7 by Thomas Friedrichsmeier.
Committed on 14/01/2016 at 19:57.
Pushed by tfry into branch 'master'.
Fix various quirks in XLConnect based XLS-import plugins, and add automated test.
M +3 -3 rkward/plugins/00saveload/import/import_xls_xlconnect.js
M +2 -2 rkward/plugins/00saveload/import/import_xls_xlconnect.xml
M +6 -0 tests/import_export_plugins.R
A +22 -0 tests/import_export_plugins/import_xls_xlconnect.rkcommands.R
A +129 -0 tests/import_export_plugins/import_xls_xlconnect.rkout
A +- -- tests/import_export_plugins_testfile.xls
A +- -- tests/import_export_plugins_testfile.xlsx
http://commits.kde.org/rkward/331411e4245f28a4c30687633d39595c0e9358c7
diff --git a/rkward/plugins/00saveload/import/import_xls_xlconnect.js b/rkward/plugins/00saveload/import/import_xls_xlconnect.js
index 7b16eea..bb33e52 100644
--- a/rkward/plugins/00saveload/import/import_xls_xlconnect.js
+++ b/rkward/plugins/00saveload/import/import_xls_xlconnect.js
@@ -19,13 +19,13 @@ function calculate (is_preview) {
var options = '';
var range = getString ("range");
- if (range) options += ', region=' + quote ("range");
+ if (range) options += ', region=' + quote (range);
else {
options += makeOption ("startRow", getString ("startrow")) + makeOption ("startCol", getString ("startcol")) + makeOption ("endRow", getString ("endrow")) + makeOption ("endCol", getString ("endcol"));
}
- if (!getBoolean ("autofitrow")) options += ', autoFitRow=FALSE';
- if (!getBoolean ("autofitcol")) options += ', autoFitCol=FALSE';
+ if (!getBoolean ("autofitrow")) options += ', autofitRow=FALSE';
+ if (!getBoolean ("autofitcol")) options += ', autofitCol=FALSE';
if (!getBoolean ("header")) options += ', header=FALSE';
options += makeOption ("rownames", getString ("rownames"));
diff --git a/rkward/plugins/00saveload/import/import_xls_xlconnect.xml b/rkward/plugins/00saveload/import/import_xls_xlconnect.xml
index 71ac9e8..a5c84c2 100644
--- a/rkward/plugins/00saveload/import/import_xls_xlconnect.xml
+++ b/rkward/plugins/00saveload/import/import_xls_xlconnect.xml
@@ -6,7 +6,7 @@
<include file="convert_encoding.xml"/>
</snippets>
<logic>
- <convert id="range_empty" mode="equals" sources="range" standard=""/>
+ <convert id="range_empty" mode="equals" sources="range.text" standard=""/>
<connect governor="range_empty" client="startrc.enabled"/>
<connect governor="range_empty" client="endrc.enabled"/>
</logic>
@@ -16,7 +16,7 @@
<browser type="file" id="file" filter="*.xls *.xlsx" label="File name" />
<input label="Index or "name" of sheet" id="sheet" initial="1" size="small" />
<frame>
- <checkbox id="header" value="TRUE" value_unchecked="FALSE" checked="false" label="Use first row as column names"/>
+ <checkbox id="header" checked="true" label="Use first row as column names"/>
<input id="rownames" initial="" size="small" label="Index or "name" of column with row names (if any)"/>
</frame>
<frame>
diff --git a/tests/import_export_plugins.R b/tests/import_export_plugins.R
index 439762a..0ae7840 100644
--- a/tests/import_export_plugins.R
+++ b/tests/import_export_plugins.R
@@ -61,6 +61,12 @@ suite <- new ("RKTestSuite", id="import_export_plugins",
rk.print (my.stata.data)
for (var in my.stata.data) rk.print (rk.get.description(var))
}, libraries=c("foreign"), files=c("../import_export_plugins_testfile.dta")),
+ new ("RKTest", id="import_xls_xlconnect", call=function () {
+ rk.call.plugin ("rkward::import_xls_xlconnect", autofitcol.state="1", autofitrow.state="1", coltypes.tsv="", doedit.state="0", endcol.real="0.00", endrow.real="7.00", file.selection="/home/thomas/develop/rkward/tests/import_export_plugins_testfile.xlsx", header.state="1", range.text="", rownames.text="", saveto.objectname="my.xls.data", saveto.parent=".GlobalEnv", sheet.text="1", startcol.real="0.00", startrow.real="0.00", submit.mode="submit")
+ rk.print (my.xls.data)
+ rk.call.plugin ("rkward::import_xls_xlconnect", autofitcol.state="1", autofitrow.state="1", coltypes.tsv="", doedit.state="0", file.selection="/home/thomas/develop/rkward/tests/import_export_plugins_testfile.xls", header.state="0", range.text="A6:B9", rownames.text="", saveto.objectname="my.xlsx.data", saveto.parent=".GlobalEnv", sheet.text="1", submit.mode="submit")
+ rk.print (my.xlsx.data)
+ }, libraries=c("XLConnect"), files=c("../import_export_plugins_testfile.xls", "../import_export_plugins_testfile.xlsx")),
new ("RKTest", id="load_source", call=function () {
stopifnot (!exists ("testx", globalenv ()))
diff --git a/tests/import_export_plugins/import_xls_xlconnect.rkcommands.R b/tests/import_export_plugins/import_xls_xlconnect.rkcommands.R
new file mode 100644
index 0000000..fc3dc12
--- /dev/null
+++ b/tests/import_export_plugins/import_xls_xlconnect.rkcommands.R
@@ -0,0 +1,22 @@
+local({
+## Prepare
+require (XLConnect)
+## Compute
+data <- readWorksheetFromFile ("/home/thomas/develop/rkward/tests/import_export_plugins_testfile.xlsx", sheet=1, startRow=0, startCol=0, endRow=7, endCol=0)
+
+.GlobalEnv$my.xls.data <- data # assign to globalenv()
+## Print result
+rk.header ("Import SPSS data", parameters=list("File name"="/home/thomas/develop/rkward/tests/import_export_plugins_testfile.xlsx",
+ "Object to save to"="my.xls.data"))
+})
+local({
+## Prepare
+require (XLConnect)
+## Compute
+data <- readWorksheetFromFile ("/home/thomas/develop/rkward/tests/import_export_plugins_testfile.xls", sheet=1, region="A6:B9", header=FALSE)
+
+.GlobalEnv$my.xlsx.data <- data # assign to globalenv()
+## Print result
+rk.header ("Import SPSS data", parameters=list("File name"="/home/thomas/develop/rkward/tests/import_export_plugins_testfile.xls",
+ "Object to save to"="my.xlsx.data"))
+})
diff --git a/tests/import_export_plugins/import_xls_xlconnect.rkout b/tests/import_export_plugins/import_xls_xlconnect.rkout
new file mode 100644
index 0000000..c11c800
--- /dev/null
+++ b/tests/import_export_plugins/import_xls_xlconnect.rkout
@@ -0,0 +1,129 @@
+<h1>Import SPSS data</h1>
+<h2>Parameters</h2>
+<ul><li>File name: /home/thomas/develop/rkward/tests/import_export_plugins_testfile.xlsx</li>
+<li>Object to save to: my.xls.data</li>
+</ul>
+DATE<br />
+
+
+<p align= center >
+<table cellspacing=0 border=1>
+<caption align=bottom class=captiondataframe></caption>
+<tr><td>
+ <table border=0 class=dataframe>
+ <tbody>
+ <tr class= firstline >
+ <th> </th>
+ <th>First.var </th>
+ <th>Second.var </th>
+ <th>Third.war </th>
+ <th>Gap </th>
+ <th>Fourth.var</th>
+ </tr>
+<tr>
+<td class=firstcolumn>1
+</td>
+<td class=cellinside>5
+</td>
+<td class=cellinside> a
+</td>
+<td class=cellinside>1.1
+</td>
+<td class=cellinside>
+</td>
+<td class=cellinside>This is a test
+</td></tr>
+
+<tr>
+<td class=firstcolumn>2
+</td>
+<td class=cellinside>4
+</td>
+<td class=cellinside>b
+</td>
+<td class=cellinside>1.2
+</td>
+<td class=cellinside>
+</td>
+<td class=cellinside>
+</td></tr>
+
+<tr>
+<td class=firstcolumn>3
+</td>
+<td class=cellinside>3
+</td>
+<td class=cellinside>c
+</td>
+<td class=cellinside>1.3
+</td>
+<td class=cellinside>
+</td>
+<td class=cellinside>This is a test
+</td></tr>
+
+<tr>
+<td class=firstcolumn>4
+</td>
+<td class=cellinside>2
+</td>
+<td class=cellinside>b
+</td>
+<td class=cellinside>1.4
+</td>
+<td class=cellinside>
+</td>
+<td class=cellinside>
+</td></tr>
+
+ </tbody>
+</table>
+ </td></table>
+ <br>
+<h1>Import SPSS data</h1>
+<h2>Parameters</h2>
+<ul><li>File name: /home/thomas/develop/rkward/tests/import_export_plugins_testfile.xls</li>
+<li>Object to save to: my.xlsx.data</li>
+</ul>
+DATE<br />
+
+
+<p align= center >
+<table cellspacing=0 border=1>
+<caption align=bottom class=captiondataframe></caption>
+<tr><td>
+ <table border=0 class=dataframe>
+ <tbody>
+ <tr class= firstline >
+ <th> </th>
+ <th>Col1 </th>
+ <th>Col2</th>
+ </tr>
+<tr>
+<td class=firstcolumn>1
+</td>
+<td class=cellinside>3
+</td>
+<td class=cellinside>c
+</td></tr>
+
+<tr>
+<td class=firstcolumn>2
+</td>
+<td class=cellinside>2
+</td>
+<td class=cellinside>b
+</td></tr>
+
+<tr>
+<td class=firstcolumn>3
+</td>
+<td class=cellinside>1
+</td>
+<td class=cellinside>b
+</td></tr>
+
+ </tbody>
+</table>
+ </td></table>
+ <br>
diff --git a/tests/import_export_plugins_testfile.xls b/tests/import_export_plugins_testfile.xls
new file mode 100644
index 0000000..967c10f
Binary files /dev/null and b/tests/import_export_plugins_testfile.xls differ
diff --git a/tests/import_export_plugins_testfile.xlsx b/tests/import_export_plugins_testfile.xlsx
new file mode 100644
index 0000000..ae8ce1d
Binary files /dev/null and b/tests/import_export_plugins_testfile.xlsx differ
More information about the rkward-tracker
mailing list