<!DOCTYPE rkplugin>
<document> 
	<code file="import_csv.php"/>
	<help file="import_csv.rkh"/>
	<logic>
		<external id="filename" />
		<connect governor="filename" client="file.selection"/>

		<convert id="quickNone" mode="equals" sources="quick.string" standard="table" />
		<convert id="quickCSV" mode="equals" sources="quick.string" standard="csv" />
		<convert id="quickCSV2" mode="equals" sources="quick.string" standard="csv2" />
		<convert id="quickTAB" mode="equals" sources="quick.string" standard="delim" />
		<convert id="quickTAB2" mode="equals" sources="quick.string" standard="delim2" />
		<convert id="quickCC2TT2" mode="notequals" sources="quick.string" standard="table" />
		
		<connect client="header.enabled" governor="quickNone" />
		<connect client="header.state" governor="quickCC2TT2" />
		<connect client="fill.state" governor="quickCC2TT2" />
		<connect client="commentchar.enabled" governor="quickNone" />
		<connect client="fill.enabled" governor="quickNone" />
		
		<convert id="quickNCT" mode="or" sources="quickNone;quickCSV;quickTAB"/>
		<connect client="dec.decPeriod.enabled" governor="quickNCT" />
		<convert id="quickNC2T2" mode="or" sources="quickNone;quickCSV2;quickTAB2"/>
		<connect client="dec.decComma.enabled" governor="quickNC2T2" />
		<connect client="dec.decOther.enabled" governor="quickNone" />
		
		<convert id="customdec" mode="equals" sources="dec.string" standard="other" />
		<connect client="custom_dec.enabled" governor="customdec" />
		<connect client="custom_dec.required" governor="custom_dec.enabled" />
		
		<convert id="quickNTT2" mode="or" sources="quickNone;quickTAB;quickTAB2"/>
		<connect client="sep.sepTab.enabled" governor="quickNTT2" />
		
		<convert id="quickNC2" mode="or" sources="quickNone;quickCSV2"/>
		<connect client="sep.sepSemiC.enabled" governor="quickNC2" />
		<convert id="quickNC" mode="or" sources="quickNone;quickCSV"/>
		<connect client="sep.sepComma.enabled" governor="quickNC" />
		<connect client="sep.sepSpace.enabled" governor="quickNone" />
		<connect client="sep.sepOther.enabled" governor="quickNone" />
		
		<convert id="customsep" mode="equals" sources="sep.string" standard="other" />
		<connect client="custom_sep.enabled" governor="customsep" />
		<connect client="custom_sep.required" governor="custom_sep.enabled" />
		
		<connect client="quote.quoteSingQ.enabled" governor="quickNone" />
		<connect client="quote.quoteDoubQSingQ.enabled" governor="quickNone" />
		<connect client="quote.quoteNone.enabled" governor="quickNone" />
		<connect client="quote.quoteOther.enabled" governor="quickNone" />
		
		<convert id="customquote" mode="equals" sources="quote.string" standard="other" />
		<connect client="custom_quote.enabled" governor="customquote" />
		<connect client="custom_quote.required" governor="custom_quote.enabled" />

		<connect client="rowname.enabled" governor="isrow.state" />
		
		<convert id="userow" mode="equals" sources="rowname.string" standard="rowcol" />
		<convert id="customizerow" mode="equals" sources="rowname.string" standard="custoRow" />
		<convert id="customizerow2" mode="and" sources="isrow.state;customizerow" standard="custoRow" />
		<connect client="nomrow.enabled" governor="userow" />
		<connect client="nomrow.required" governor="userow" />
		<connect client="rownames.enabled" governor="customizerow" />
		<connect client="rownames.required" governor="customizerow" />

		<convert id="customizecol" mode="equals" sources="colname.string" standard="custoCol" />
		<connect client="colnames.enabled" governor="customizecol" />
		<connect client="colnames.required" governor="customizecol" />
		<convert id="customizeclasses" mode="equals" sources="colclass.string" standard="custoClass" />
		<connect client="custoClasses.enabled" governor="customizeclasses" />
		<connect client="custoClasses.required" governor="customizeclasses" />
	</logic>
	<dialog label="Import Text / CSV data" >
		<tabbook>
			<tab id="tab_general" label="General" >
				<browser id="file" type="file" label="File name"/>
				<row>
					<saveobject id="name" initial="my.csv.data" label="Object to save to"/>
					<checkbox id="doedit" value="1" value_unchecked="0" label="Edit Object" checked="true" />
				</row>
				<row>
					<column>
						<radio id="quick" label="Quick mode" >
							<option value="table" label="None" checked="true"/>
							<option value="csv" label="CSV" />
							<option value="csv2" label="CSV2" />
							<option value="delim" label="TAB" />
							<option value="delim2" label="TAB2" />
						</radio>
					</column>
					<column>
						<checkbox id="header" value="TRUE" value_unchecked="FALSE" checked="false" label="Column names in first row"/>
						<radio id="dec" label="Decimal point character" >
							<option id="decPeriod" value="'.'" label="'.' (Period)" />
							<option id="decComma" value="','" label="',' (Comma)" />
							<option id="decOther" value="other" label="Other (specify below)" />
						</radio>
						<input id="custom_dec" label="Specify decimal point character" />
					</column>
					<column>
						<radio id="sep" label="Field separator character" >
							<option id="sepTab" value="'\t'" label="Tab" />
							<option id="sepSemiC" value="';'" label="';' (Semicolon)" />
							<option id="sepComma" value="','" label="',' (Comma)" />
							<option id="sepSpace" value="' '" label="Space" />
							<option id="sepOther" value="other" label="Other (specify below)" />
						</radio>
						<input id="custom_sep" label="Specify field separator character" />
					</column>
				</row>
			</tab>
			<tab id="tab_rows" label="Rows and Columns" >
				<row>
					<column>
						<frame label="Row Specifications">
							<checkbox value_unchecked="false" checked="false" value="true" id="isrow" label="Customize row names" />
							<radio id="rowname" label="Rows names" >
								<option value="NULL" label="Number" />
								<option value="rowcol" label="As specified in column x:" />
								<option value="custoRow" label="Use a vector" />
							</radio>
							<input size="small" id="nomrow" initial="1" label="Column number or variable name" />
							<input id="rownames" label="Vector of row names (quoted)" />
						</frame>
					</column>
					<column>
						<frame label="Column Specifications">
							<radio id="colname" label="Column names" >
								<option value="" label="Default" />
								<option value="custoCol" label="Use a character vector" />
							</radio>
							<input id="colnames" label="Vector of column names (quoted)" />
						<checkbox id="flush" label="Skip any further fields" value=", flush=TRUE" value_unchecked="" />
							<radio id="colclass" label="Classes of columns" >
								<option value="" label="Default" />
								<option value="custoClass" label="Use a character vector" />
							</radio>
							<input id="custoClasses" label="Vector of column classes (quoted)" />
						</frame>
					</column>
				</row>
			</tab>
			
			<tab id="tab_further_options" label="Further Options" >
				<row>
				<column>
					<checkbox id="allow_escapes" label="Allow escaped characters" value=", allowEscapes=TRUE" value_unchecked="" />
					<radio id="strings_as_factors" label="Convert character columns to factors" >
						<option value=", stringsAsFactors=TRUE" label="Convert to factor" />
						<option value="" label="Default" checked="true" />
						<option value=", stringsAsFactors=FALSE" label="Do not convert" />
					</radio>
					<radio id="quote" label="String delimiter" >
						<option id="quoteDoubQ" value="'\&quot;'" label="&quot; only" />
						<option id="quoteSingQ" value="'\''" label="' only" />
						<option id="quoteDoubQSingQ" value="'&quot;\''" label="&quot; and '" checked="true"/>
						<option id="quoteNone" value="''" label="None / disabled" />
						<option id="quoteOther" value="other" label="Other (specify below)" />
					</radio>
					<input id="custom_quote" label="Specify quoting character(s)" />
				</column>
				<column>
						<input size="small" initial="0" id="skip" label="Skip x lines at the start of the file" />
						<input size="small" initial="-1" id="nrows" label="Max number of lines to read (-1 for no limit)" />
						<input size="small" initial="NA" id="na" label="Character for missing values" />
						<input size="small" initial="#" id="commentchar" label="Character for comments" />
					<checkbox id="fill" checked="false" value="TRUE" value_unchecked="FALSE" label="Fill the rows if unequal length" />
					<checkbox value_unchecked="FALSE" checked="true" value="TRUE" id="checkname" label="Check syntax of the variables names" />
					<checkbox value_unchecked="FALSE" checked="false" value="TRUE" id="stripwhite" label="Strip white values" />
					<checkbox value_unchecked="FALSE" checked="true" value="TRUE" id="blanklinesskip" label="Skip blank lines" />
				</column>
			</row>
			</tab>
		</tabbook>
	</dialog>
</document>
