// globals


function quoteString (string) {
	return ('"' + strtr (string, array ('"', '\\"')) + '"');
}


function calculate () {
	quick = getValue ("quick");
	if (quick == "table") {
		dec = getValue ("dec");
		if (dec == "other") dec = quoteString (getValue ("custom_dec"));
		sep = getValue ("sep");
		if (sep == "other") sep = quoteString (getValue ("custom_sep"));
		quote = getValue ("quote");
		if (quote == "other") quote = quoteString (getValue ("custom_quote"));
		header = getValue ("header");
		fill = getValue ("fill");
		comchar = quoteString (getValue ("commentchar"));
		tableOptions = ", header={$header}, sep={$sep}, quote={$quote}, dec={$dec}, fill={$fill}, comment.char={$comchar}";
	} else {
		tableOptions = "";
	}

echo ('imported <<- read.' + quick + ' (file="' + getValue("file") + '"' + tableOptions + ', '); # doing row names (what a pity+++) 
	if (getValue("rowname")!="NULL") {
		echo ("row.names = ");
		if (getValue("rowname")=="rowcol") echo (echo (getValue("nomrow")) + ",");
		else echo (getValue("rownames") + ",");
	}
	# doing col names (what a pity+++)
	if (getValue("colname") == "custoCol") echo ("col.names = " + getValue ("colnames") + ",");
	# doing col class (what a pity+++)
	if (getValue("colclass") == "custoClass") echo ("colClasses = " + getValue ("custoClasses") + ",");
	#doing what is left
echo (' na.strings = "' + getValue("na"))  echo ('", nrows = ' + getValue("nrows") + ', skip = ' + getValue("skip") + ', check.names = ' + getValue("checkname") + ', strip.white = ' + getValue("stripwhite") + ', blank.lines.skip = ' + getValue("blanklinesskip") + getValue("allow_escapes") + getValue("flush") + getValue("strings_as_factors") + ')\n');
echo ('\n');
echo ('# copy from the local environment to globalenv()\n');
echo ('assign("' + getValue("name") + '", imported, envir=globalenv())\n');
	if (getValue ("doedit")) { 
echo ('\n');
echo ('rk.edit (' + getValue ("name") + ')\n');
	}
}

function printout () { 
	makeHeaderCode ("Import text / csv data", array ("File" ,  getValue ("file"), "Import as" ,  getValue ("name")));
}

