[rkward-cvs] [rkward] rkward/plugins: added the new table/CSV export dialog for better testing. also added a help page and included the generator script.
m.eik michalke
meik.michalke at uni-duesseldorf.de
Tue Dec 2 21:54:50 UTC 2014
Git commit 7f335afee024f3afbecd20530f8da44ea6055c6e by m.eik michalke.
Committed on 02/12/2014 at 21:53.
Pushed by meikm into branch 'master'.
added the new table/CSV export dialog for better testing. also added a help page and included the generator script.
A +108 -0 rkward/plugins/00saveload/save/write_csv.js
A +94 -0 rkward/plugins/00saveload/save/write_csv.rkh
A +178 -0 rkward/plugins/00saveload/save/write_csv.xml
M +3 -1 rkward/plugins/import_export.pluginmap
A +459 -0 rkward/plugins/rkwarddev_scripts/write_csv.R
http://commits.kde.org/rkward/7f335afee024f3afbecd20530f8da44ea6055c6e
diff --git a/rkward/plugins/00saveload/save/write_csv.js b/rkward/plugins/00saveload/save/write_csv.js
new file mode 100644
index 0000000..55cb178
--- /dev/null
+++ b/rkward/plugins/00saveload/save/write_csv.js
@@ -0,0 +1,108 @@
+// this code was generated using the rkwarddev package.
+//perhaps don't make changes here, but in the rkwarddev script instead!
+
+
+
+function preprocess(){
+ // add requirements etc. here
+
+}
+
+function calculate(){
+ // read in variables from dialog
+ var x = getString("x");
+ var file = getString("file");
+ var append = getBoolean("append");
+ var quick = getString("quick");
+ var dec = getString("dec");
+ var customDec = getString("custom_dec");
+ var sep = getString("sep");
+ var customSep = getString("custom_sep");
+ var rowname = getString("rowname");
+ var custRowNames = getString("custRowNames");
+ var colname = getString("colname");
+ var custColNames = getString("custColNames");
+ var encoding = getString("encoding");
+ var userEncoding = getString("user_encoding");
+ var quote = getBoolean("quote");
+ var qmethod = getString("qmethod");
+ var na = getString("na");
+ var eol = getString("eol");
+
+ // the R code to be evaluated
+ if(quick == "csv" || quick == "csv2") {
+ echo("\n\t# some options can't be changed with write." + quick + "() and are set to these values:\n" + "\t# append=FALSE, sep=\"" + sep + "\", dec=\"" + dec + "\"");
+ if(rowname == "TRUE") {
+ echo(", col.names=NA");
+ } else {
+ echo(", col.names=TRUE");
+ }
+ echo(", qmethod=\"double\"");
+ }
+ if(quick != "delim" && quick != "delim2") {
+ echo("\n\twrite." + quick + "(");
+ } else {
+ echo("\n\twrite.table(");
+ }
+ echo("\n\t\tx=" + x);
+ echo(",\n\t\tfile=\"" + file + "\"");
+ if(quick != "csv" && quick != "csv2") {
+ if(append) {
+ echo(",\n\t\tappend=TRUE");
+ }
+ }
+ if(!quote) {
+ echo(",\n\t\tquote=FALSE");
+ }
+ if(quick != "csv" && quick != "csv2" && sep != " ") {
+ if(sep != "other") {
+ echo(",\n\t\tsep=\"" + sep + "\"");
+ } else if(customSep != " ") {
+ echo(",\n\t\tsep=\"" + customSep + "\"");
+ }
+ }
+ if(eol != "\\n") {
+ echo(",\n\t\teol=\"" + eol + "\"");
+ }
+ if(na != "NA") {
+ echo(",\n\t\tna=\"" + na + "\"");
+ }
+ if(quick != "csv" && quick != "csv2" && dec != ".") {
+ if(dec != "other") {
+ echo(",\n\t\tdec=\"" + dec + "\"");
+ } else if(customDec != ".") {
+ echo(",\n\t\tdec=\"" + customDec + "\"");
+ }
+ }
+ if(rowname == "custoRow") {
+ echo(",\n\t\trow.names=" + custRowNames);
+ } else if(rowname != "TRUE") {
+ echo(",\n\t\trow.names=" + rowname);
+ }
+ if(quick != "csv" && quick != "csv2") {
+ if(colname == "custoCol") {
+ echo(",\n\t\tcol.names=" + custColNames);
+ } else if(colname != "TRUE") {
+ echo(",\n\t\tcol.names=" + colname);
+ }
+ }
+ if(quick != "csv" && quick != "csv2" && qmethod != "escape") {
+ echo(",\n\t\tqmethod=\"" + qmethod + "\"");
+ }
+ if(encoding != "other") {
+ echo(",\n\t\tfileEncoding=\"" + encoding + "\"");
+ } else if(userEncoding != "") {
+ echo(",\n\t\tfileEncoding=\"" + userEncoding + "\"");
+ }
+ echo("\n\t)\n\n");
+}
+
+function printout(){
+ // printout the results
+
+
+ new Header(i18n("Export Table / CSV files")).addFromUI("file").addFromUI("x").print();
+
+
+}
+
diff --git a/rkward/plugins/00saveload/save/write_csv.rkh b/rkward/plugins/00saveload/save/write_csv.rkh
new file mode 100644
index 0000000..2924036
--- /dev/null
+++ b/rkward/plugins/00saveload/save/write_csv.rkh
@@ -0,0 +1,94 @@
+<!DOCTYPE rkhelp >
+<document>
+ <!-- this code was generated using the rkwarddev package.
+ perhaps don't make changes here, but in the rkwarddev script instead! -->
+ <title>
+ Export Table / CSV files
+ </title>
+ <summary>
+ Export data to CSV or similar file formats.
+ </summary>
+ <usage>
+ Select a tabular data object (like a data frame or matrix) and chose a file to save to. All other options allow you to define the file format, handling of column and row names as well as special character handling.
+ </usage>
+ <!-- <section id="sct_EDITORDE" title="EDIT OR DELETE ME">
+ EDIT OR DELETE ME
+ </section> -->
+ <settings>
+ <caption id="tab_DtndFlFr" />
+ <caption id="frm_vrsltdxlDS" />
+ <setting id="x">
+ Select a data object to export. Valid data types are array, data.frame, matrix, character, numeric, and integer.
+ </setting>
+ <caption id="frm_Saveto" />
+ <setting id="file">
+ The file to save to. Existing files will be overwritten, unless the append option is checked.
+ </setting>
+ <setting id="append">
+ Should existing files be overwritten or the data appended? If this is greyed out, the selected preset sets this for you.
+ </setting>
+ <setting id="quick">
+ Select one of the default file formats here. They will set some of the options (like field separator and decimal point) with resonable defaults. Use the custom format if you need more control.
+ </setting>
+ <caption id="frm_rDPPCCCOFT" />
+ <setting id="dec">
+ Specify the desirend decimal point character. If this is greyed out, the selected preset sets this for you.
+ </setting>
+ <setting id="custom_dec">
+ Use this value as the custom decimal point character.
+ </setting>
+ <setting id="sep">
+ Specify the desirend field separator character. If this is greyed out, the selected preset sets this for you.
+ </setting>
+ <setting id="custom_sep">
+ Use this value as the custom field separator character.
+ </setting>
+ <caption id="tab_RwsndClm" />
+ <caption id="frm_Rwspcfct" />
+ <setting id="rowname">
+ Decide how to deal with row names.
+ </setting>
+ <setting id="custRowNames">
+ Select a character vector to use for custom row names.
+ </setting>
+ <caption id="frm_Clmnspcf" />
+ <setting id="colname">
+ Decide how to deal with column names. If this is greyed out, the selected preset sets this for you.
+ </setting>
+ <setting id="custColNames">
+ Select a character vector to use for custom column names.
+ </setting>
+ <caption id="tab_EncdngCO" />
+ <caption id="frm_Encoding" />
+ <setting id="encoding">
+ If the default character encoding doesn't work for you, you can set a specific one here.
+ </setting>
+ <setting id="user_encoding">
+ Use this field to set a custom encoding, in case the dropdown menu doesn't list the one you need.
+ </setting>
+ <caption id="frm_rQHEEDDQHE" />
+ <setting id="quote">
+ Check this to have all string values quoted.
+ </setting>
+ <setting id="qmethod">
+ Controls how existing quotes in values are handled -- they can either be escaped or double qouted. If this is greyed out, the selected preset sets this for you.
+ </setting>
+ <setting id="na">
+ Set the character to indicate missing data.
+ </setting>
+ <setting id="eol">
+ Set the character used to indicate a line break (EOL). This varies between operating systems, changing this option might help in case you run into problems when exchanging files with other people.
+ </setting>
+ </settings>
+ <related>
+ <ul>
+ <li>
+ <link href="rkward://rhelp/write.table">
+ R manual page for write.table(), which is called by this plugin.
+ </link>
+ </li>
+ </ul>
+ </related>
+ <technical>
+ </technical>
+</document>
diff --git a/rkward/plugins/00saveload/save/write_csv.xml b/rkward/plugins/00saveload/save/write_csv.xml
new file mode 100644
index 0000000..1ea5904
--- /dev/null
+++ b/rkward/plugins/00saveload/save/write_csv.xml
@@ -0,0 +1,178 @@
+<!DOCTYPE rkplugin >
+<document>
+ <!-- this code was generated using the rkwarddev package.
+ perhaps don't make changes here, but in the rkwarddev script instead! -->
+ <code file="write_csv.js" />
+ <help file="write_csv.rkh" />
+ <logic>
+ <external id="filename" />
+ <connect governor="filename.state" client="file.selection" />
+ <convert id="customEnc" sources="encoding.string" mode="equals" standard="other" />
+ <connect governor="customEnc" client="user_encoding.enabled" />
+ <convert id="quickNone" sources="quick.string" mode="equals" standard="table" />
+ <convert id="quickCSV" sources="quick.string" mode="equals" standard="csv" />
+ <convert id="quickCSV2" sources="quick.string" mode="equals" standard="csv2" />
+ <convert id="quickTAB" sources="quick.string" mode="equals" standard="delim" />
+ <convert id="quickTAB2" sources="quick.string" mode="equals" standard="delim2" />
+ <convert id="quickCC2TT2" sources="quick.string" mode="notequals" standard="table" />
+ <convert id="quickNCT" sources="quickNone;quickCSV;quickTAB" mode="or" />
+ <connect governor="quickNCT" client="dec.decPeriod.enabled" />
+ <convert id="quickNC2T2" sources="quickNone;quickCSV2;quickTAB2" mode="or" />
+ <connect governor="quickNC2T2" client="dec.decComma.enabled" />
+ <connect governor="quickNone" client="dec.decOther.enabled" />
+ <convert id="customdec" sources="dec.string" mode="equals" standard="other" />
+ <connect governor="customdec" client="custom_dec.enabled" />
+ <convert id="customsep" sources="sep.string" mode="equals" standard="other" />
+ <connect governor="customsep" client="custom_sep.enabled" />
+ <convert id="quickNTT2" sources="quickNone;quickTAB;quickTAB2" mode="or" />
+ <connect governor="quickNTT2" client="sep.sepTab.enabled" />
+ <convert id="quickNC2" sources="quickNone;quickCSV2" mode="or" />
+ <connect governor="quickNC2" client="sep.sepSemiC.enabled" />
+ <convert id="quickNC" sources="quickNone;quickCSV" mode="or" />
+ <connect governor="quickNC" client="sep.sepComma.enabled" />
+ <connect governor="quickNone" client="sep.sepSpace.enabled" />
+ <connect governor="quickNone" client="sep.sepOther.enabled" />
+ <convert id="quickCC2" sources="quickCSV;quickCSV2" mode="or" />
+ <connect governor="quickCC2.not" client="append.enabled" />
+ <connect governor="quickCC2.not" client="frm_Clmnspcf.enabled" />
+ <connect governor="quickCC2.not" client="qmethod.qmethodEsc.enabled" />
+ <convert id="customizerow" sources="rowname.string" mode="equals" standard="custoRow" />
+ <connect governor="customizerow" client="custRowNames.enabled" />
+ <convert id="customizecol" sources="colname.string" mode="equals" standard="custoCol" />
+ <connect governor="customizecol" client="custColNames.enabled" />
+ </logic>
+ <dialog label="Export Table / CSV files">
+ <tabbook>
+ <tab label="Data and File Format" id="tab_DtndFlFr">
+ <row id="row_cSSSSDSDSS">
+ <column id="clm_vrslctrdSS">
+ <varselector id="vrs_Slctvrbl" label="Select a variable or table" />
+ </column>
+ <column id="clm_frmDSDSSSA">
+ <frame id="frm_vrsltdxlDS">
+ <varslot id="x" label="Data" source="vrs_Slctvrbl" classes="array data.frame matrix character numeric integer" required="true" />
+ </frame>
+ <frame label="Save to" id="frm_Saveto">
+ <browser label="" type="savefile" id="file" />
+ <checkbox id="append" label="Append to file (if it exists)" value="true" />
+ </frame>
+ </column>
+ </row>
+ <row id="row_cFCCSVSCSV">
+ <column id="clm_dFCCSVSCSV">
+ <dropdown id="quick" label="File format">
+ <option label="Comma separated values (CSV)" value="csv" checked="true" />
+ <option label="Semicolon separated values, comma as decimal separator (CSV2)" value="csv2" />
+ <option label="Tab separated values (TAB)" value="delim" />
+ <option label="Tab separated values, comma as decimal separator (TAB2)" value="delim2" />
+ <option label="Custom" value="table" />
+ </dropdown>
+ <frame id="frm_rDPPCCCOFT">
+ <row id="row_cDPPCCCOFT">
+ <column id="col_decimal">
+ <radio id="dec" label="Decimal point character">
+ <option label="'.' (Period)" value="." checked="true" id="decPeriod" />
+ <option label="',' (Comma)" value="," id="decComma" />
+ <option label="Custom (specify below)" value="other" id="decOther" />
+ </radio>
+ <stretch />
+ <input label="" id="custom_dec" required="true" />
+ </column>
+ <column id="col_field">
+ <radio id="sep" label="Field separator character">
+ <option label="Tab" value="\t" id="sepTab" />
+ <option label="';' (Semicolon)" value=";" id="sepSemiC" />
+ <option label="',' (Comma)" value="," id="sepComma" />
+ <option label="Space" value=" " checked="true" id="sepSpace" />
+ <option label="Custom (specify below)" value="other" id="sepOther" />
+ </radio>
+ <stretch />
+ <input label="" id="custom_sep" required="true" />
+ </column>
+ </row>
+ </frame>
+ </column>
+ </row>
+ </tab>
+ <tab label="Rows and Columns" id="tab_RwsndClm">
+ <row id="row_cSSRRRUTRU">
+ <column id="select_rowcol_names">
+ <varselector id="vrs_Slctrwrc" label="Select row or column names" />
+ </column>
+ <column id="clm_fRRRUTRUE1">
+ <frame label="Row specifications" id="frm_Rwspcfct">
+ <radio id="rowname" label="Row names">
+ <option label="Use current row names" value="TRUE" id="temp1" />
+ <option label="No names" value="FALSE" id="temp2" />
+ <option label="Custom (specify below)" value="custoRow" />
+ </radio>
+ <varslot id="custRowNames" label="Row names (character vector)" source="vrs_Slctrwrc" classes="character" required="true" />
+ <stretch />
+ </frame>
+ <frame label="Column specifications" id="frm_Clmnspcf">
+ <radio id="colname" label="Column names">
+ <option label="Use current column names" value="TRUE" />
+ <option label="No names" value="FALSE" />
+ <option label="Custom (specify below)" value="custoCol" />
+ </radio>
+ <varslot id="custColNames" label="Column names (character vector)" source="vrs_Slctrwrc" classes="character" required="true" />
+ <stretch />
+ </frame>
+ </column>
+ </row>
+ </tab>
+ <tab label="Encoding and Character Options" id="tab_EncdngCO">
+ <row id="row_cEEFUTF8UT">
+ <column id="clm_fEEFUTF8UT">
+ <frame label="Encoding" id="frm_Encoding">
+ <dropdown id="encoding" label="File encoding">
+ <option label="(default)" value="" checked="true" />
+ <option label="UTF-8" value="UTF-8" />
+ <option label="Latin 1" value="latin1" />
+ <option label="ISO8859-1 Latin-1 Western European" value="ISO8859-1" />
+ <option label="ISO8859-2 Latin-2 Central European" value="ISO8859-2" />
+ <option label="ISO8859-3 Latin-3 South European" value="ISO8859-3" />
+ <option label="ISO8859-4 Latin-4 North European" value="ISO8859-4" />
+ <option label="ISO8859-5 Latin/Cyrillic" value="ISO8859-5" />
+ <option label="ISO8859-6 Latin/Arabic" value="ISO8859-6" />
+ <option label="ISO8859-7 Latin/Greek" value="ISO8859-7" />
+ <option label="MS-GREEK" value="MS-GREEK" />
+ <option label="ISO8859-8 Latin/Hebrew" value="ISO8859-8" />
+ <option label="ISO8859-9 Latin-5 Turkish" value="ISO8859-9" />
+ <option label="ISO8859-10 Latin-6 Nordic" value="ISO8859-10" />
+ <option label="ISO8859-11 Latin/Thai" value="ISO8859-11" />
+ <option label="ISO8859-13 Latin-7 Baltic Rim" value="ISO8859-13" />
+ <option label="ISO8859-14 Latin-8 Celtic" value="ISO8859-14" />
+ <option label="ISO8859-15 Latin-9 Western European (EUR)" value="ISO8859-15" />
+ <option label="ISO8859-16 Latin-10 South-Eastern European" value="ISO8859-16" />
+ <option label="Other (specify below)" value="other" />
+ </dropdown>
+ <input label="Custom encoding" id="user_encoding" required="true" />
+ </frame>
+ <stretch />
+ <frame id="frm_rQHEEDDQHE">
+ <row id="row_cQHEEDDQHE">
+ <column id="clm_chckQHEEDD">
+ <checkbox id="quote" label="Quote all strings" value="true" checked="true" />
+ <radio id="qmethod" label="Handling double quote characters">
+ <option label="Escape" value="escape" checked="true" id="qmethodEsc" />
+ <option label="Double" value="double" id="qmethodDbl" />
+ </radio>
+ </column>
+ <column id="clm_iCNANLFGNU">
+ <input label="Character for missing values" id="na" initial="NA" size="small" />
+ <dropdown id="eol" label="Newline character">
+ <option label="\n (LF: GNU/Linux, BSD, OS X)" value="\n" checked="true" />
+ <option label="\r\n (CR+LF: Windows, DOS)" value="\r\n" />
+ <option label="\r (CR: Mac OS <= 9)" value="\r" />
+ <option label="\n\r (LF+CR: RISC OS)" value="\n\r" />
+ </dropdown>
+ </column>
+ </row>
+ </frame>
+ </column>
+ </row>
+ </tab>
+ </tabbook>
+ </dialog>
+</document>
diff --git a/rkward/plugins/import_export.pluginmap b/rkward/plugins/import_export.pluginmap
index 034a38d..1b33a1b 100644
--- a/rkward/plugins/import_export.pluginmap
+++ b/rkward/plugins/import_export.pluginmap
@@ -14,6 +14,7 @@
<component type="standard" id="save_skeleton" file="save/skeleton/description.xml" label="Create package skeleton" />
<component type="standard" id="save_variables" file="save/write.xml" label="Export vector or matrix data" />
<component type="standard" id="save_table" file="save/write_table.xml" label="Export tabular data" />
+ <component type="standard" id="save_csv" file="save/write_csv.xml" label="Export Table / CSV files" />
<component type="standard" id="import_spss" file="import/import_spss.xml" label="Import SPSS">
<attribute id="format" value="*.sav *.por" label="SPSS data files"/>
@@ -42,7 +43,8 @@
<menu id="export" label="Export">
<entry component="save_r" />
<entry component="save_variables" />
- <entry component="save_table" />
+ <entry component="save_table" />
+ <entry component="save_csv" />
<entry component="save_skeleton" />
</menu>
</menu>
diff --git a/rkward/plugins/rkwarddev_scripts/write_csv.R b/rkward/plugins/rkwarddev_scripts/write_csv.R
new file mode 100644
index 0000000..c8f4047
--- /dev/null
+++ b/rkward/plugins/rkwarddev_scripts/write_csv.R
@@ -0,0 +1,459 @@
+local({
+## Vorbereiten
+require(rkwarddev)
+rkwarddev.required("0.06-5")
+
+# define where the plugin should write its files
+output.dir <- tempdir()
+# overwrite an existing plugin in output.dir?
+overwrite <- TRUE
+# if you set guess.getters to TRUE, the resulting code will need RKWard >= 0.6.0
+guess.getter <- TRUE
+
+## Berechne
+about.plugin <- rk.XML.about(
+ name="Export Table / CSV files",
+ author=person(given="m.eik", family="michalke", email="meik.michalke at uni-duesseldorf.de", role=c("aut", "cre")),
+ about=list(desc="Export data in table/CSV format", version="0.01-0", license="GPL (>= 3)", category="export")
+)
+
+# name of the main component, relevant for help page content
+rk.set.comp("Export Table / CSV files")
+
+############
+## your plugin dialog and JavaScript should be put here
+############
+
+etc.var.select <- rk.XML.varselector("Select a variable or table")
+etc.var.data <- rk.XML.varslot("Data", source=etc.var.select, required=TRUE,
+ classes=c("array", "data.frame", "matrix", "character", "numeric", "integer"),
+ id.name="x",
+ help="Select a data object to export. Valid data types are array, data.frame, matrix, character, numeric, and integer."
+)
+
+etc.browser <- rk.XML.browser("", type="savefile", id.name="file",
+ help="The file to save to. Existing files will be overwritten, unless the append option is checked."
+)
+
+etc.dropdown.encoding <- rk.XML.dropdown("File encoding",
+ options=list(
+ "(default)"=c(val="", chk=TRUE),
+ "UTF-8"=c(val="UTF-8"),
+ "Latin 1"=c(val="latin1"),
+ "ISO8859-1 Latin-1 Western European"=c(val="ISO8859-1"),
+ "ISO8859-2 Latin-2 Central European"=c(val="ISO8859-2"),
+ "ISO8859-3 Latin-3 South European"=c(val="ISO8859-3"),
+ "ISO8859-4 Latin-4 North European"=c(val="ISO8859-4"),
+ "ISO8859-5 Latin/Cyrillic"=c(val="ISO8859-5"),
+ "ISO8859-6 Latin/Arabic"=c(val="ISO8859-6"),
+ "ISO8859-7 Latin/Greek"=c(val="ISO8859-7"),
+ "MS-GREEK"=c(val="MS-GREEK"),
+ "ISO8859-8 Latin/Hebrew"=c(val="ISO8859-8"),
+ "ISO8859-9 Latin-5 Turkish"=c(val="ISO8859-9"),
+ "ISO8859-10 Latin-6 Nordic"=c(val="ISO8859-10"),
+ "ISO8859-11 Latin/Thai"=c(val="ISO8859-11"),
+ "ISO8859-13 Latin-7 Baltic Rim"=c(val="ISO8859-13"),
+ "ISO8859-14 Latin-8 Celtic"=c(val="ISO8859-14"),
+ "ISO8859-15 Latin-9 Western European (EUR)"=c(val="ISO8859-15"),
+ "ISO8859-16 Latin-10 South-Eastern European"=c(val="ISO8859-16"),
+ "Other (specify below)"=c(val="other")
+ ),
+ id.name="encoding",
+ help="If the default character encoding doesn't work for you, you can set a specific one here."
+)
+etc.input.encoding <- rk.XML.input("Custom encoding", required=TRUE, id.name="user_encoding",
+ help="Use this field to set a custom encoding, in case the dropdown menu doesn't list the one you need."
+)
+
+
+etc.drop.format <- rk.XML.dropdown("File format",
+ options=list(
+ "Comma separated values (CSV)"=c(val="csv", chk="true"),
+ "Semicolon separated values, comma as decimal separator (CSV2)"=c(val="csv2"),
+ "Tab separated values (TAB)"=c(val="delim"),
+ "Tab separated values, comma as decimal separator (TAB2)"=c(val="delim2"),
+ "Custom"=c(val="table")
+ ),
+ id.name="quick",
+ help="Select one of the default file formats here. They will set some of the options (like field separator and decimal point) with resonable defaults. Use the custom format if you need more control."
+)
+
+etc.frame.characters <- rk.XML.frame(
+ rk.XML.row(
+ rk.XML.col(
+ etc.radio.decimal <- rk.XML.radio("Decimal point character",
+ options=list(
+ etc.radio.decimal.opt.period <- rk.XML.option("'.' (Period)", val=".", id.name="decPeriod", chk=TRUE),
+ etc.radio.decimal.opt.comma <- rk.XML.option("',' (Comma)", val=",", id.name="decComma"),
+ etc.radio.decimal.opt.other <- rk.XML.option("Custom (specify below)", val="other", id.name="decOther")
+ ),
+ id.name="dec",
+ help="Specify the desirend decimal point character. If this is greyed out, the selected preset sets this for you."
+ ),
+ rk.XML.stretch(),
+ etc.input.decimal <- rk.XML.input("", required=TRUE, id="custom_dec",
+ help="Use this value as the custom decimal point character."),
+ id.name="col_decimal"
+ ),
+ rk.XML.col(
+ etc.radio.field <- rk.XML.radio("Field separator character",
+ options=list(
+ etc.radio.field.opt.tab <- rk.XML.option("Tab", val="\\t", id.name="sepTab"),
+ etc.radio.field.opt.semcl <- rk.XML.option("';' (Semicolon)", val=";", id.name="sepSemiC"),
+ etc.radio.field.opt.comma <- rk.XML.option("',' (Comma)", val=",", id.name="sepComma"),
+ etc.radio.field.opt.space <- rk.XML.option("Space", val=" ", id.name="sepSpace", chk=TRUE),
+ etc.radio.field.opt.other <- rk.XML.option("Custom (specify below)", val="other", id.name="sepOther")
+ ),
+ id.name="sep",
+ help="Specify the desirend field separator character. If this is greyed out, the selected preset sets this for you."
+ ),
+ rk.XML.stretch(),
+ etc.input.field <- rk.XML.input("", required=TRUE, id="custom_sep",
+ help="Use this value as the custom field separator character."),
+ id.name="col_field"
+ )
+ )
+)
+
+etc.frame.specialChars <- rk.XML.frame(
+ rk.XML.row(
+ rk.XML.col(
+ etc.cbox.quote <- rk.XML.cbox("Quote all strings", id.name="quote", chk=TRUE,
+ help="Check this to have all string values quoted."),
+ etc.radio.quote <- rk.XML.radio("Handling double quote characters",
+ options=list(
+ etc.radio.quote.opt.escape <- rk.XML.option("Escape", val="escape", id.name="qmethodEsc", chk=TRUE),
+ etc.radio.quote.opt.double <- rk.XML.option("Double", val="double", id.name="qmethodDbl")
+ ),
+ id.name="qmethod",
+ help="Controls how existing quotes in values are handled -- they can either be escaped or double qouted. If this is greyed out, the selected preset sets this for you."
+ )
+ ),
+ rk.XML.col(
+ etc.input.na <- rk.XML.input("Character for missing values", initial="NA", size="small", id.name="na",
+ help="Set the character to indicate missing data."
+ ),
+ etc.dropdown.eol <- rk.XML.dropdown("Newline character",
+ options=list(
+ "\\n (LF: GNU/Linux, BSD, OS X)"=c(val="\\n", chk=TRUE),
+ "\\r\\n (CR+LF: Windows, DOS)"=c(val="\\r\\n"),
+ "\\r (CR: Mac OS <= 9)"=c(val="\\r"),
+ "\\n\\r (LF+CR: RISC OS)"=c(val="\\n\\r")
+ ),
+ id.name="eol",
+ help="Set the character used to indicate a line break (EOL). This varies between operating systems, changing this option might help in case you run into problems when exchanging files with other people."
+ )
+ )
+ )
+)
+
+
+etc.var.rc.select <- rk.XML.varselector("Select row or column names")
+etc.var.rc.rows <- rk.XML.varslot("Row names (character vector)", source=etc.var.rc.select, required=TRUE,
+ classes=c("character"), id.name="custRowNames",
+ help="Select a character vector to use for custom row names."
+)
+etc.var.rc.cols <- rk.XML.varslot("Column names (character vector)", source=etc.var.rc.select, required=TRUE,
+ classes=c("character"), id.name="custColNames",
+ help="Select a character vector to use for custom column names.")
+
+etc.frame.specs.rows <- rk.XML.frame(
+ etc.radio.rownames <- rk.XML.radio("Row names",
+ options=list(
+ etc.radio.rownames.names.rows <- rk.XML.option("Use current row names", val="TRUE", id.name="temp1"),
+ etc.radio.rownames.names.none <- rk.XML.option("No names", val="FALSE", id.name="temp2"),
+ etc.radio.rownames.names.custom <- rk.XML.option("Custom (specify below)", val="custoRow")
+ ),
+ id.name="rowname",
+ help="Decide how to deal with row names."
+ ),
+ etc.var.rc.rows,
+ rk.XML.stretch(),
+ label="Row specifications"
+)
+etc.frame.specs.cols <- rk.XML.frame(
+ etc.radio.colnames <- rk.XML.radio("Column names",
+ options=list(
+ etc.radio.colnames.names.cols <- rk.XML.option("Use current column names", val="TRUE"),
+ etc.radio.colnames.names.none <- rk.XML.option("No names", val="FALSE"),
+ etc.radio.colnames.names.custom <- rk.XML.option("Custom (specify below)", val="custoCol")
+ ),
+ id.name="colname",
+ help="Decide how to deal with column names. If this is greyed out, the selected preset sets this for you."
+ ),
+ etc.var.rc.cols,
+ rk.XML.stretch(),
+ label="Column specifications"
+)
+
+etc.tabs <- rk.XML.tabbook(tabs=list(
+ "Data and File Format"=list(
+ rk.XML.row(
+ rk.XML.col(
+ etc.var.select
+ ),
+ rk.XML.col(
+ rk.XML.frame(
+ etc.var.data
+ ),
+ rk.XML.frame(
+ etc.browser,
+ etc.cbox.append <- rk.XML.cbox("Append to file (if it exists)", id.name="append",
+ help="Should existing files be overwritten or the data appended? If this is greyed out, the selected preset sets this for you."
+ ),
+ label="Save to"
+ )
+ )
+ ),
+ rk.XML.row(
+ rk.XML.col(
+ etc.drop.format,
+ etc.frame.characters
+ )
+ )
+ ),
+ "Rows and Columns"=list(
+ rk.XML.row(
+ rk.XML.col(
+ etc.var.rc.select,
+ id.name="select_rowcol_names"
+ ),
+ rk.XML.col(
+ etc.frame.specs.rows,
+ etc.frame.specs.cols
+ )
+ )
+ ),
+ "Encoding and Character Options"=list(
+ rk.XML.row(
+ rk.XML.col(
+ rk.XML.frame(
+ etc.dropdown.encoding,
+ etc.input.encoding,
+ label="Encoding"
+ ),
+ rk.XML.stretch(),
+ etc.frame.specialChars
+ )
+ )
+ )
+ )
+)
+
+etc.dialog <- rk.XML.dialog(etc.tabs, label="Export Table / CSV files")
+
+## logic
+
+etc.logic <- rk.XML.logic(
+ etc.external <- rk.XML.external("filename"),
+ rk.XML.connect(governor=etc.external, client=etc.browser, set="selection"),
+
+ customEnc <- rk.XML.convert(sources=list(string=etc.dropdown.encoding), mode=c(equals="other"), id.name="customEnc"),
+ rk.XML.connect(governor=customEnc, client=etc.input.encoding),
+
+ quickNone <- rk.XML.convert(sources=list(string=etc.drop.format), mode=c(equals="table"), id.name="quickNone"),
+ quickCSV <- rk.XML.convert(sources=list(string=etc.drop.format), mode=c(equals="csv"), id.name="quickCSV"),
+ quickCSV2 <- rk.XML.convert(sources=list(string=etc.drop.format), mode=c(equals="csv2"), id.name="quickCSV2"),
+ quickTAB <- rk.XML.convert(sources=list(string=etc.drop.format), mode=c(equals="delim"), id.name="quickTAB"),
+ quickTAB2 <- rk.XML.convert(sources=list(string=etc.drop.format), mode=c(equals="delim2"), id.name="quickTAB2"),
+ quickCC2TT2 <- rk.XML.convert(sources=list(string=etc.drop.format), mode=c(notequals="table"), id.name="quickCC2TT2"),
+
+ quickNCT <- rk.XML.convert(sources=list(quickNone, quickCSV, quickTAB), mode=c(or=""), id.name="quickNCT"),
+ rk.XML.connect(governor=quickNCT, client=etc.radio.decimal.opt.period),
+ quickNC2T2 <- rk.XML.convert(sources=list(quickNone, quickCSV2, quickTAB2), mode=c(or=""), id.name="quickNC2T2"),
+ rk.XML.connect(governor=quickNC2T2, client=etc.radio.decimal.opt.comma),
+ rk.XML.connect(governor=quickNone, client=etc.radio.decimal.opt.other),
+
+ customdec <- rk.XML.convert(sources=list(string=etc.radio.decimal), mode=c(equals="other"), id.name="customdec"),
+ rk.XML.connect(governor=customdec, client=etc.input.decimal),
+
+ customsep <- rk.XML.convert(sources=list(string=etc.radio.field), mode=c(equals="other"), id.name="customsep"),
+ rk.XML.connect(governor=customsep, client=etc.input.field),
+
+ quickNTT2 <- rk.XML.convert(sources=list(quickNone, quickTAB, quickTAB2), mode=c(or=""), id.name="quickNTT2"),
+ rk.XML.connect(governor=quickNTT2, client=etc.radio.field.opt.tab),
+ quickNC2 <- rk.XML.convert(sources=list(quickNone, quickCSV2), mode=c(or=""), id.name="quickNC2"),
+ rk.XML.connect(governor=quickNC2, client=etc.radio.field.opt.semcl),
+ quickNC <- rk.XML.convert(sources=list(quickNone, quickCSV), mode=c(or=""), id.name="quickNC"),
+ rk.XML.connect(governor=quickNC, client=etc.radio.field.opt.comma),
+ rk.XML.connect(governor=quickNone, client=etc.radio.field.opt.space),
+ rk.XML.connect(governor=quickNone, client=etc.radio.field.opt.other),
+
+ quickCC2 <- rk.XML.convert(sources=list(quickCSV, quickCSV2), mode=c(or=""), id.name="quickCC2"),
+ rk.XML.connect(governor=quickCC2, client=etc.cbox.append, not=TRUE),
+ rk.XML.connect(governor=quickCC2, client=etc.frame.specs.cols, not=TRUE),
+ rk.XML.connect(governor=quickCC2, client=etc.radio.quote.opt.escape, not=TRUE),
+
+ customizerow <- rk.XML.convert(sources=list(string=etc.radio.rownames), mode=c(equals="custoRow"), id.name="customizerow"),
+ rk.XML.connect(governor=customizerow, client=etc.var.rc.rows),
+
+ customizecol <- rk.XML.convert(sources=list(string=etc.radio.colnames), mode=c(equals="custoCol"), id.name="customizecol"),
+ rk.XML.connect(governor=customizecol, client=etc.var.rc.cols)#,
+)
+
+## JavaScript
+
+etc.JS <- rk.paste.JS(
+ ite(id(etc.drop.format, " == \"csv\" || ", etc.drop.format, " == \"csv2\""),
+ rk.paste.JS(
+ echo(
+ "\n\t# some options can't be changed with write.", etc.drop.format, "() and are set to these values:\n",
+ "\t# append=FALSE, sep=\"", etc.radio.field, "\", dec=\"", etc.radio.decimal, "\""
+ ),
+ ite(id(etc.radio.rownames, " == \"TRUE\""),
+ echo(", col.names=NA"),
+ echo(", col.names=TRUE")
+ ),
+ echo(", qmethod=\"double\"")
+ )
+ ),
+ ite(id(etc.drop.format, " != \"delim\" && ", etc.drop.format, " != \"delim2\""),
+ echo("\n\twrite.", etc.drop.format, "("),
+ echo("\n\twrite.table(")
+ ),
+ echo("\n\t\tx=", etc.var.data),
+ # file=etc.browser, # default=""
+ echo(",\n\t\tfile=\"", etc.browser, "\""),
+
+ # append=etc.cbox.append, # default=FALSE
+ # csv, csv2: hide
+ ite(id(etc.drop.format, " != \"csv\" && ", etc.drop.format, " != \"csv2\""),
+ tf(etc.cbox.append, opt="append")
+ ),
+ # quote=etc.radio.quote, # default=TRUE
+ tf(etc.cbox.quote, true=FALSE, not=TRUE, opt="quote"),
+
+ # sep=etc.radio.field, # default=" ",
+ # csv, csv2: hide
+ # delim, delim2: sep="\t",
+ ite(id(etc.drop.format, " != \"csv\" && ", etc.drop.format, " != \"csv2\" && ", etc.radio.field, " != \" \""),
+ ite(id(etc.radio.field, " != \"other\""),
+ echo(",\n\t\tsep=\"", etc.radio.field, "\""),
+ ite(id(etc.input.field, " != \" \""),
+ echo(",\n\t\tsep=\"", etc.input.field, "\"")
+ )
+ )
+ ),
+
+ # eol=etc.dropdown.eol, # default="\n",
+ ite(id(etc.dropdown.eol, " != \"\\\\n\""),
+ echo(",\n\t\teol=\"", etc.dropdown.eol, "\"")
+ ),
+ # na=etc.input.na, # default="NA",
+ ite(id(etc.input.na, " != \"NA\""),
+ echo(",\n\t\tna=\"", etc.input.na, "\"")
+ ),
+
+ # dec=etc.radio.decimal, # default=".",
+ # csv, csv2: hide
+ # delim: dec="."
+ # delim2: dec=","
+ ite(id(etc.drop.format, " != \"csv\" && ", etc.drop.format, " != \"csv2\" && ", etc.radio.decimal, " != \".\""),
+ ite(id(etc.radio.decimal, " != \"other\""),
+ echo(",\n\t\tdec=\"", etc.radio.decimal, "\""),
+ ite(id(etc.input.decimal, " != \".\""),
+ echo(",\n\t\tdec=\"", etc.input.decimal, "\"")
+ )
+ )
+ ),
+
+ # row.names=etc.radio.rownames, # default=TRUE, etc.var.rc.rows
+ ite(id(etc.radio.rownames, " == \"custoRow\""),
+ echo(",\n\t\trow.names=", etc.var.rc.rows),
+ ite(id(etc.radio.rownames, " != \"TRUE\""),
+ echo(",\n\t\trow.names=", etc.radio.rownames)
+ )
+ ),
+
+ # col.names=etc.radio.colnames, # default=TRUE, etc.var.rc.cols
+ # csv, csv2: hide
+ ite(id(etc.drop.format, " != \"csv\" && ", etc.drop.format, " != \"csv2\""),
+ ite(id(etc.radio.colnames, " == \"custoCol\""),
+ echo(",\n\t\tcol.names=", etc.var.rc.cols),
+ ite(id(etc.radio.colnames, " != \"TRUE\""),
+ echo(",\n\t\tcol.names=", etc.radio.colnames)
+ )
+ )
+ ),
+
+ # qmethod=etc.radio.quote, # default="escape"
+ # csv, csv2: hide
+ ite(id(etc.drop.format, " != \"csv\" && ", etc.drop.format, " != \"csv2\" && ", etc.radio.quote, " != \"escape\""),
+ echo(",\n\t\tqmethod=\"", etc.radio.quote, "\"")
+ ),
+
+ # fileEncoding=, # default=""
+ ite(id(etc.dropdown.encoding, " != \"other\""),
+ echo(",\n\t\tfileEncoding=\"", etc.dropdown.encoding, "\""),
+ ite(id(etc.input.encoding, " != \"\""),
+ echo(",\n\t\tfileEncoding=\"", etc.input.encoding, "\"")
+ )
+ ),
+
+ # closing bracket of write function
+ echo("\n\t)\n\n")
+)
+
+etc.JS.printout <- rk.paste.JS(
+ rk.JS.header("Export Table / CSV files", addFromUI=etc.browser, addFromUI=etc.var.data)
+)
+
+
+############
+## help file
+
+etc.rkh.summary <- rk.rkh.summary("Export data to CSV or similar file formats.")
+
+etc.rkh.usage <- rk.rkh.usage("Select a tabular data object (like a data frame or matrix) and chose a file to save to. All other options allow you to define the file format, handling of column and row names as well as special character handling.")
+
+etc.rkh.related <- rk.rkh.related(rk.rkh.link("write.table", "R manual page for write.table(), which is called by this plugin."))
+
+
+#############
+## the main call
+## if you run the following function call, files will be written to output.dir!
+#############
+# this is where things get serious, that is, here all of the above is put together into one plugin
+plugin.dir <- rk.plugin.skeleton(
+ about=about.plugin,
+ path=output.dir,
+ guess.getter=guess.getter,
+ scan=c("var", "saveobj", "settings"),
+ xml=list(
+ dialog=etc.dialog,
+ #wizard=,
+ logic=etc.logic#,
+ #snippets=
+ ),
+ js=list(
+ results.header=FALSE,
+ #load.silencer=,
+ #require=,
+ #variables=,
+ #globals=,
+ #preprocess=,
+ calculate=etc.JS,
+ printout=etc.JS.printout#,
+ #doPrintout=
+ ),
+ rkh=list(
+ summary=etc.rkh.summary,
+ usage=etc.rkh.usage,
+ #sections=,
+ #settings=,
+ related=etc.rkh.related#,
+ #technical=
+ ),
+ create=c("pmap", "xml", "js", "desc", "rkh"),
+ overwrite=overwrite,
+ #components=list(),
+ #provides=c("logic", "dialog"),
+ pluginmap=list(name="Export Table / CSV files", hierarchy=list("file", "export")),
+ #dependencies=plugin.dependencies,
+ tests=FALSE,
+ edit=FALSE,
+ load=TRUE,
+ show=TRUE
+)
+
+})
More information about the rkward-tracker
mailing list