title: How to handle binary strings in R?
body: <p>R is not able to cope with null-strings (\0) in characters, does anyone know how to handle this? More concrete, I want to store complex R objects within a database using an ODBC or JDBC connection. Since complex R objects are not easily to be mapped to dataframes, I need a different possibility to store such objects. An object could be for example:</p>
  
  <pre><code>library(kernlab)
  data(iris)
  model &lt;- ksvm(Species ~ ., data=iris, type="C-bsvc", kernel="rbfdot", kpar="automatic", C=10) 
  </code></pre>
  
  <p>Because >model&lt; cannot be stored directly in a database, I use the serialize() function to retrieve a binary representation of the object (in order to store it in a BLOB column):</p>
  
  <pre><code> serialModel &lt;- serialize(model, NULL)
  </code></pre>
  
  <p>Now I would like to store this via ODBC/JDBC. To do so, I need a string representation of the object in order to send a query to the database, e.g. INSERT INTO. Since the result is a vector of type raw vector, I need to convert it:</p>
  
  <pre><code> stringModel &lt;- rawToChar(serialModel)
  </code></pre>
  
  <p>And there is the problem: </p>
  
  <pre><code>Error in rawToChar(serialModel) : 
    embedded nul in string: 'X\n\0\0\0\002\0\002\v\0......
  </code></pre>
  
  <p>R is not able to deal with \0 in strings. Does anyone has an idea how to bypass this restriction? Or is there probably a completly different approach to achieve this goal?</p>
  
  <p>Thanks in advance</p>