{"id":779,"date":"2015-02-22T17:50:52","date_gmt":"2015-02-23T00:50:52","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=779"},"modified":"2015-02-22T17:50:52","modified_gmt":"2015-02-23T00:50:52","slug":"readworksheet-methods-xlconnect","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2015\/02\/22\/readworksheet-methods-xlconnect\/","title":{"rendered":"readWorksheet-methods {XLConnect}"},"content":{"rendered":"<div class=\"field field-type-text field-field-sub-title\">\n<div class=\"field-items\">\n<div class=\"field-item odd\">Reading data from worksheets<\/div>\n<\/div>\n<\/div>\n<div class=\"rdoc-meta\">\n<div class=\"field field-type-text field-field-package\">\n<div class=\"field-items\">\n<div class=\"field-item odd\">\n<div class=\"field-label-inline-first\">Package:<\/div>\n<p>XLConnect<\/p><\/div>\n<\/div>\n<\/div>\n<div class=\"field field-type-text field-field-pkg-version\">\n<div class=\"field-items\">\n<div class=\"field-item odd\">\n<div class=\"field-label-inline-first\">Version:<\/div>\n<p>0.2-7<\/p><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"rdoc-content\">\n<div class=\"rdoc-description\">\n<h3>Description<\/h3>\n<p>Reads data from worksheets of a <span class=\"geshifilter\"><code class=\"r geshifilter-r\">workbook<\/code><\/span>.<\/p>\n<\/div>\n<div class=\"rdoc-usage\">\n<h3>Usage<\/h3>\n<pre class=\"rdoc-monospace\"> \n## S4 method for class 'workbook,numeric':\nreadWorksheet((object,sheet,startRow,startCol,endRow,endCol,autofitRow,autofitCol,\nregion,header,rownames,colTypes,forceConversion,dateTimeFormat,check.names,\nuseCachedValues,keep,drop, simplify, readStrategy))\n\n## S4 method for class 'workbook,character':\nreadWorksheet((object,sheet,startRow,startCol,endRow,endCol,autofitRow,autofitCol,\nregion,header,rownames,colTypes,forceConversion,dateTimeFormat,check.names,\nuseCachedValues,keep,drop, simplify, readStrategy))\n\n<\/pre>\n<\/div>\n<div class=\"rdoc-arg-list\">\n<h3>Arguments<\/h3>\n<dl class=\"rdoc-args\">\n<dt>object<\/dt>\n<dd>The <span class=\"geshifilter\"><code class=\"r geshifilter-r\">workbook<\/code><\/span> to use<\/dd>\n<dt>sheet<\/dt>\n<dd>The name or index of the worksheet to read from<\/dd>\n<dt>startRow<\/dt>\n<dd>The index of the first row to read from. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">\u00a0<\/code><\/span> meaning that the start row is determined automatically.<\/dd>\n<dt>startCol<\/dt>\n<dd>The index of the first column to read from. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">\u00a0<\/code><\/span> meaning that the start column is determined automatically.<\/dd>\n<dt>endRow<\/dt>\n<dd>The index of the last row to read from. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">\u00a0<\/code><\/span> meaning that the end row is determined automatically.<\/dd>\n<dt>endCol<\/dt>\n<dd>The index of the last column to read from. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">\u00a0<\/code><\/span> meaning that the end column is determined automatically.<\/dd>\n<dt>autofitRow<\/dt>\n<dd><span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span> specifying if leading and trailing empty rows should be skipped. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">TRUE<\/code><\/span>.<\/dd>\n<dt>autofitCol<\/dt>\n<dd><span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span> specifying if leading and trailing empty columns should be skipped. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">TRUE<\/code><\/span>.<\/dd>\n<dt>region<\/dt>\n<dd>A range specifier in the form &#8216;A10:B18&#8217;. This provides an alternative way to specify <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startRow<\/code><\/span>,<span class=\"geshifilter\"><code class=\"r geshifilter-r\">startCol<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endRow<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endCol<\/code><\/span>. Range specifications take precedence over index specifications.<\/dd>\n<dt>header<\/dt>\n<dd>Interpret the first row of the specified area as column headers. The default is <span class=\"geshifilter\"><code class=\"r geshifilter-r\">TRUE<\/code><\/span>.<\/dd>\n<dt>rownames<\/dt>\n<dd>Index (<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/numeric\">numeric<\/a><\/code><\/span>) or name (<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span>) of column that should be used as row names. The corresponding column will be removed from the data set. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">NULL<\/code><\/span> which means that no row names are applied. Row names must be either <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/integer\">integer<\/a><\/code><\/span> or <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span>. Non-numeric columns will be coerced to <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span>.<\/dd>\n<dt>colTypes<\/dt>\n<dd>Column types to use when reading in the data. Specified as a <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span> vector of the corresponding type names (see <span class=\"geshifilter\"><code class=\"r geshifilter-r\">XLC<\/code><\/span>; <span class=\"geshifilter\"><code class=\"r geshifilter-r\">XLC$DATA_TYPE.&lt;?&gt;<\/code><\/span>). You may also use R class names such as <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/numeric\">numeric<\/a><\/code><\/span>,<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">POSIXt<\/code><\/span>. The types are applied in the given order to the columns &#8211; elements are recycled if necessary. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a>(0)<\/code><\/span> meaning that column types are determined automatically (see the Note section for more information).<br \/>\nBy default, type conversions are only applied if the specified column type is a more generic type (e.g. from Numeric to String) &#8211; otherwise <span class=\"geshifilter\"><code class=\"r geshifilter-r\">NA<\/code><\/span> is returned. The <span class=\"geshifilter\"><code class=\"r geshifilter-r\">forceConversion<\/code><\/span> flag can be set to force conversion into less generic types where possible.<\/dd>\n<dt>forceConversion<\/dt>\n<dd><span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span> specifying if conversions to less generic types should be forced. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">FALSE<\/code><\/span> meaning that if a column is specified to be of a certain type via the <span class=\"geshifilter\"><code class=\"r geshifilter-r\">colTypes<\/code><\/span> argument and a more generic type is detected in the column, then <span class=\"geshifilter\"><code class=\"r geshifilter-r\">NA<\/code><\/span> will be returned (example: column is specified to be DateTime but a more generic String is found). Specifying <span class=\"geshifilter\"><code class=\"r geshifilter-r\">forceConversion = TRUE<\/code><\/span> will try to enforce a conversion &#8211; if it succeeds the corresponding (converted) value will be returned, otherwise <span class=\"geshifilter\"><code class=\"r geshifilter-r\">NA<\/code><\/span>. See the Note section for some additional information.<\/dd>\n<dt>dateTimeFormat<\/dt>\n<dd>Date\/time format used when doing date\/time conversions. Defaults to<br \/>\n<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/getOption\">getOption<\/a>(\"XLConnect.dateTimeFormat\")<\/code><\/span>. This should be a POSIX format specifier according to<span class=\"geshifilter\"><code class=\"r geshifilter-r\">strptime<\/code><\/span> although not all specifications have been implemented yet &#8211; the most important ones however are available.<\/dd>\n<dt>check.names<\/dt>\n<dd><span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span> specifying if column names of the resulting <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\">data.frame<\/a><\/code><\/span> should be checked to ensure that they are syntactically valid variable names and are not duplicated. See the <span class=\"geshifilter\"><code class=\"r geshifilter-r\">check.names<\/code><\/span> argument of<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\">data.frame<\/a><\/code><\/span>. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">TRUE<\/code><\/span>.<\/dd>\n<dt>useCachedValues<\/dt>\n<dd><span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span> specifying whether to read cached formula results from the workbook instead of re-evaluating them. This is particularly helpful in cases for reading data produced by Excel features not supported in XLConnect like references to external workbooks. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">FALSE<\/code><\/span>, which means that formulas will be evaluated by XLConnect.<\/dd>\n<dt>keep<\/dt>\n<dd>Vector of column names or indices to be kept in the output data frame. It is possible to specify either<span class=\"geshifilter\"><code class=\"r geshifilter-r\">keep<\/code><\/span> or <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/drop\">drop<\/a><\/code><\/span>, but not both at the same time. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">NULL<\/code><\/span>. If a vector is passed as argument, it will be wrapped into a list. This list gets replicated to match the length of the other arguments. Example: if<span class=\"geshifilter\"><code class=\"r geshifilter-r\">sheet = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(\"Sheet1\", \"Sheet2\", \"Sheet3\")<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">keep = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2)<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">keep<\/code><\/span> will be internally converted into <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(<a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2))<\/code><\/span> and then replicated to match the number of sheets, i.e. <span class=\"geshifilter\"><code class=\"r geshifilter-r\">keep =<a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(<a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2), <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2), <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2))<\/code><\/span>. The result is that the first two columns of each sheet are kept. If<span class=\"geshifilter\"><code class=\"r geshifilter-r\">keep = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(1,2)<\/code><\/span> is specified, it will be replicated as <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(1,2,1)<\/code><\/span>, i.e. respectively the first, second and first column of the sheets &#8220;Sheet1&#8221;, &#8220;Sheet2&#8221;, &#8220;Sheet3&#8221; will be kept.<\/dd>\n<dt>drop<\/dt>\n<dd>Vector of column names or indices to be dropped in the output data frame. It is possible to specify either<span class=\"geshifilter\"><code class=\"r geshifilter-r\">keep<\/code><\/span> or <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/drop\">drop<\/a><\/code><\/span>, but not both at the same time. Defaults to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">NULL<\/code><\/span>. If a vector is passed as argument, it will be wrapped into a list. This list gets replicated to match the length of the other arguments. Example: if<span class=\"geshifilter\"><code class=\"r geshifilter-r\">sheet = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(\"Sheet1\", \"Sheet2\", \"Sheet3\")<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/drop\">drop<\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2)<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/drop\">drop<\/a><\/code><\/span> will be internally converted into <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(<a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2))<\/code><\/span> and then replicated to match the number of sheets, i.e. <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/drop\">drop<\/a> =<a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(<a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2), <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2), <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,2))<\/code><\/span>. The result is that the first two columns of each sheet are dropped. If <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/drop\">drop<\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(1,2)<\/code><\/span> is specified, it will be replicated as <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a>(1,2,1)<\/code><\/span>, i.e. respectively the first, second and first column of the sheets &#8220;Sheet1&#8221;, &#8220;Sheet2&#8221;, &#8220;Sheet3&#8221; will be dropped.<\/dd>\n<dt>simplify<\/dt>\n<dd><span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span> specifying if the result should be simplified, e.g. in case the <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\">data.frame<\/a><\/code><\/span> would only have one row or one column (and data types match). Simplifying here is identical to calling <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/unlist\">unlist<\/a><\/code><\/span> on the otherwise resulting <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\">data.frame<\/a><\/code><\/span> (using <span class=\"geshifilter\"><code class=\"r geshifilter-r\">use.names = FALSE<\/code><\/span>). The default is <span class=\"geshifilter\"><code class=\"r geshifilter-r\">FALSE<\/code><\/span>.<\/dd>\n<dt>readStrategy<\/dt>\n<dd><span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span> specifying the reading strategy to use. Currently supported strategies are:<\/p>\n<ul>\n<li><span class=\"geshifilter\"><code class=\"r geshifilter-r\">\"default\"<\/code><\/span> (default): Can handle all supported data types incl. date\/time values and can deal directly with missing value identifiers (see <span class=\"geshifilter\"><code class=\"r geshifilter-r\">setMissingValue<\/code><\/span>)<\/li>\n<li><span class=\"geshifilter\"><code class=\"r geshifilter-r\">\"fast\"<\/code><\/span>: Increased read performance. Date\/time values are read as numeric (number of days since 1900-01-01; fractional days represent hours, minutes, and seconds) and only blank cells are recognized as missing (missing value identifiers as set in <span class=\"geshifilter\"><code class=\"r geshifilter-r\">setMissingValue<\/code><\/span> are ignored)<\/li>\n<\/ul>\n<\/dd>\n<\/dl>\n<\/div>\n<div class=\"rdoc-details\">\n<h3>Details<\/h3>\n<p>Reads data from the worksheet specified by <span class=\"geshifilter\"><code class=\"r geshifilter-r\">sheet<\/code><\/span>. Data is read starting at the top left corner specified by<span class=\"geshifilter\"><code class=\"r geshifilter-r\">startRow<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startCol<\/code><\/span> down to the bottom right corner specified by <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endRow<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endCol<\/code><\/span>. If <span class=\"geshifilter\"><code class=\"r geshifilter-r\">header =TRUE<\/code><\/span>, the first row is interpreted as column names of the resulting <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\">data.frame<\/a><\/code><\/span>.<br \/>\nIf <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startRow &lt;= 0<\/code><\/span> then the first available row in the sheet is assumed. If <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endRow &lt;= 0<\/code><\/span> then the last available row in the sheet is assumed. If <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startCol &lt;= 0<\/code><\/span> then the minimum column between <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startRow<\/code><\/span>and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endRow<\/code><\/span> is assumed. If <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endCol &lt;= 0<\/code><\/span> then the maximum column between <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startRow<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endRow<\/code><\/span> is assumed. In other words, if no boundaries are specified <span class=\"geshifilter\"><code class=\"r geshifilter-r\">readWorksheet<\/code><\/span> assumes the &#8220;bounding box&#8221; of the data as the corresponding boundaries.<br \/>\nThe arguments <span class=\"geshifilter\"><code class=\"r geshifilter-r\">autofitRow<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">autofitCol<\/code><\/span> (both defaulting to <span class=\"geshifilter\"><code class=\"r geshifilter-r\">TRUE<\/code><\/span>) can be used to skip leading and trailing empty rows even in case <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startRow<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endRow<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startCol<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endCol<\/code><\/span> are specified to values <span class=\"geshifilter\"><code class=\"r geshifilter-r\">&gt; 0<\/code><\/span>. This can be useful if data is expected within certain given boundaries but the exact location is not available.<\/p>\n<p>If all four coordinate arguments are missing this behaves as above with <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startRow = 0<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">startCol = 0<\/code><\/span>,<span class=\"geshifilter\"><code class=\"r geshifilter-r\">endRow = 0<\/code><\/span> and <span class=\"geshifilter\"><code class=\"r geshifilter-r\">endCol = 0<\/code><\/span>. In this case <span class=\"geshifilter\"><code class=\"r geshifilter-r\">readWorksheet<\/code><\/span> assumes the &#8220;bounding box&#8221; of the data as the corresponding boundaries.<\/p>\n<p>All arguments (except <span class=\"geshifilter\"><code class=\"r geshifilter-r\">object<\/code><\/span>) are vectorized. As such, multiple worksheets (and also multiple data regions from the same worksheet) can be read with one method call. If only one single data region is read, the return value is a <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\">data.frame<\/a><\/code><\/span>. If multiple data regions are specified, the return value is a <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a><\/code><\/span> of<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/data.frame\">data.frame<\/a><\/code><\/span>&#8216;s returned in the order they have been specified. If worksheets have been specified by name, the <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a><\/code><\/span> will be a named <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\">list<\/a><\/code><\/span> named by the corresponding worksheets.<\/p>\n<\/div>\n<div class=\"rdoc-note\">\n<h3>Note<\/h3>\n<p>If no specific column types (see argument <span class=\"geshifilter\"><code class=\"r geshifilter-r\">colTypes<\/code><\/span>) are specified, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">readWorksheet<\/code><\/span> tries to determine the resulting column types based on the read cell types. If different cell types are found in a specific column, the most general of those is used and mapped to the corresponding R data type. The order of data types from least to most general is Boolean (<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/logical\">logical<\/a><\/code><\/span>) &lt; DateTime (<span class=\"geshifilter\"><code class=\"r geshifilter-r\">POSIXct<\/code><\/span>) &lt; Numeric (<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/numeric\">numeric<\/a><\/code><\/span>) &lt; String (<span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span>). E.g. if a column is read that contains cells of type Boolean, Numeric and String then the resulting column in R would be <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span> since <span class=\"geshifilter\"><code class=\"r geshifilter-r\"><a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\">character<\/a><\/code><\/span> is the most general type.<\/p>\n<p>Some additional information with respect to forcing data type conversion using <span class=\"geshifilter\"><code class=\"r geshifilter-r\">forceConversion =TRUE<\/code><\/span>:<\/p>\n<ul>\n<li>Forcing conversion from String to Boolean: <span class=\"geshifilter\"><code class=\"r geshifilter-r\">TRUE<\/code><\/span> is returned if and only if the target string is &#8220;true&#8221; (ignoring any capitalization). Any other string will return <span class=\"geshifilter\"><code class=\"r geshifilter-r\">FALSE<\/code><\/span>.<\/li>\n<li>Forcing conversion from Numeric to DateTime: since Excel understands Dates\/Times as Numerics with some additional formatting, a conversion from a Numeric to a DateTime is actually possible. Numerics in this case represent the number of days since 1900-01-01. Fractional days represent hours, minutes, and seconds.<\/li>\n<\/ul>\n<\/div>\n<div class=\"rdoc-seealso\">\n<h3>See Also<\/h3>\n<p><span class=\"geshifilter\"><code class=\"r geshifilter-r\">workbook<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">writeWorksheet<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">readNamedRegion<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">writeNamedRegion<\/code><\/span>,<br \/>\n<span class=\"geshifilter\"><code class=\"r geshifilter-r\">readWorksheetFromFile<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">readTable<\/code><\/span>, <span class=\"geshifilter\"><code class=\"r geshifilter-r\">onErrorCell<\/code><\/span><\/p>\n<\/div>\n<div class=\"rdoc-examples\">\n<h3>Examples<\/h3>\n<div class=\"geshifilter\">\n<pre class=\"r geshifilter-r\">## Example 1:\n# mtcars xlsx file from demoFiles subfolder of package XLConnect\ndemoExcelFile &lt;- <a href=\"http:\/\/inside-r.org\/r-doc\/base\/system.file\">system.file<\/a>(\"demoFiles\/mtcars.xlsx\", package = \"XLConnect\")\n\u00a0\n# Load workbook\nwb &lt;- loadWorkbook(demoExcelFile)\n\u00a0\n# Read worksheet 'mtcars' (providing no specific area bounds;\n# with default header = TRUE)\n<a href=\"http:\/\/inside-r.org\/r-doc\/utils\/data\">data<\/a> &lt;- readWorksheet(wb, sheet = \"mtcars\")\n\u00a0\n\u00a0\n## Example 2:\n# mtcars xlsx file from demoFiles subfolder of package XLConnect\ndemoExcelFile &lt;- <a href=\"http:\/\/inside-r.org\/r-doc\/base\/system.file\">system.file<\/a>(\"demoFiles\/mtcars.xlsx\", package = \"XLConnect\")\n\u00a0\n# Load workbook\nwb &lt;- loadWorkbook(demoExcelFile)\n\u00a0\n# Read worksheet 'mtcars' (providing area bounds; with default header = TRUE)\n<a href=\"http:\/\/inside-r.org\/r-doc\/utils\/data\">data<\/a> &lt;- readWorksheet(wb, sheet = \"mtcars\", startRow = 1, startCol = 3,\n                      endRow = 15, endCol = 8)\n\u00a0\n\u00a0\n## Example 3:\n# mtcars xlsx file from demoFiles subfolder of package XLConnect\ndemoExcelFile &lt;- <a href=\"http:\/\/inside-r.org\/r-doc\/base\/system.file\">system.file<\/a>(\"demoFiles\/mtcars.xlsx\", package = \"XLConnect\")\n\u00a0\n# Load workbook\nwb &lt;- loadWorkbook(demoExcelFile)\n\u00a0\n# Read worksheet 'mtcars' (providing area bounds using the region argument;\n# with default header = TRUE)\n<a href=\"http:\/\/inside-r.org\/r-doc\/utils\/data\">data<\/a> &lt;- readWorksheet(wb, sheet = \"mtcars\", region = \"C1:H15\")\n\u00a0\n\u00a0\n## Example 4:\n# conversion xlsx file from demoFiles subfolder of package XLConnect\nexcelFile &lt;- <a href=\"http:\/\/inside-r.org\/r-doc\/base\/system.file\">system.file<\/a>(\"demoFiles\/conversion.xlsx\", package = \"XLConnect\")\n\u00a0\n# Load workbook\nwb &lt;- loadWorkbook(excelFile)\n\u00a0\n# Read worksheet 'Conversion' with pre-specified column types\n# Note: in the worksheet all data was entered as strings!\n# forceConversion = TRUE is used to force conversion from String\n# into the less generic data types Numeric, DateTime &amp; Boolean\n<a href=\"http:\/\/inside-r.org\/r-doc\/stats\/df\">df<\/a> &lt;- readWorksheet(wb, sheet = \"Conversion\", header = TRUE,\n                    colTypes = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(XLC$DATA_TYPE.NUMERIC,\n                                 XLC$DATA_TYPE.DATETIME,\n                                 XLC$DATA_TYPE.BOOLEAN),\n                    forceConversion = TRUE,\n                    dateTimeFormat = \"%Y-%m-%d %H:%M:%S\")\n\u00a0\n## Example 5:\n# mtcars xlsx file from demoFiles subfolder of package XLConnect\ndemoExcelFile &lt;- <a href=\"http:\/\/inside-r.org\/r-doc\/base\/system.file\">system.file<\/a>(\"demoFiles\/mtcars.xlsx\", package = \"XLConnect\")\n\u00a0\n# Load workbook\nwb &lt;- loadWorkbook(demoExcelFile)\n\u00a0\n# Read the columns 1, 3 and 5 from the sheet 'mtcars' (with default header = TRUE)\n<a href=\"http:\/\/inside-r.org\/r-doc\/utils\/data\">data<\/a> &lt;- readWorksheet(wb, sheet = \"mtcars\", keep=<a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\">c<\/a>(1,3,5))<\/pre>\n<\/div>\n<\/div>\n<div class=\"rdoc-author\">\n<h3>Author(s)<\/h3>\n<p>Martin Studer<br \/>\nThomas Themel<br \/>\nNicola Lambiase<br \/>\nMirai Solutions GmbH <a href=\"http:\/\/www.mirai-solutions.com\/\">http:\/\/www.mirai-solutions.com<\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Reading data from worksheets Package: XLConnect Version: 0.2-7 Description Reads data from worksheets of a workbook. Usage ## S4 method for class &#8216;workbook,numeric&#8217;: readWorksheet((object,sheet,startRow,startCol,endRow,endCol,autofitRow,autofitCol, region,header,rownames,colTypes,forceConversion,dateTimeFormat,check.names,&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-779","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=779"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/779\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}