title: Specifying Column Types when Importing xlsx Data to R with Package readxl
body: <p>I'm importing <code>xlsx</code> 2007 tables into <code>R 3.2.1patched</code> using package <code>readxl 0.1.0</code> under <code>Windows 7 64</code>.  The tables' size is on the order of 25,000 rows by 200 columns.</p>
  
  <p>Function <code>read_excel()</code> works a treat. My only problem is with its assignment of column class (datatype) to sparsely populated columns.  For example, a given column may be NA for 20,000 rows and then will take a character value on row 20,001. <code>read_excel()</code> appears to default to column type numeric when scanning the first n rows of a column and finding <code>NAs</code> only. The data causing the problem are chars in a column assigned numeric. When the error limit is reached, execution halts. I actually want the data in the sparse columns, so setting the error limit higher isn't a solution.</p>
  
  <p>I can identify the troublesome columns by reviewing the warnings thrown. And <code>read_excel()</code> has an option for asserting a column's datatype by setting argument <code>col_types</code> according to the package docs: </p>
  
  <p><strong>Either <code>NULL</code> to guess from the spreadsheet or a character vector containing <code>blank</code>,<code>numeric</code>, <code>date</code> or <code>text</code>.</strong></p>
  
  <p>But does this mean I have to construct a vector of length 200 populated in almost every position with <code>blank</code> and <code>text</code> in handful of positions corresponding to the offending columns?</p>
  
  <p>There's probably a way of doing this in a couple lines of <code>R</code> code. Create a vector of the required length and fill it with <code>blank</code>s.  Maybe another vector containing the numbers of the columns to be forced to <code>text</code>, and then ... Or maybe it's possible to call out for <code>read_excel()</code> just the columns for which its guesses aren't as desired.</p>
  
  <p>I'd appreciate any suggestions. </p>
  
  <p>Thanks in advance.</p>