title: amazon S3 bucket access with Rstudio
body: <p>I have successfully accessed and queried amazon redshift with R (rstudio) using RPostgreSQL where I have</p>
  
  <pre><code>drv &lt;- dbDriver("PostgreSQL")
  con &lt;- dbConnect(drv, host="****.redshift.amazonaws.com", port=5439,dbname="***", user="***", password="****")
  </code></pre>
  
  <p>I can then run my query with:</p>
  
  <pre><code>dbGetQuery(con,"SELECT DISTINCT(vin) FROM rawdata")
  </code></pre>
  
  <p>While my queries dont take too long to run, saving my files to my personal computer do. I think it would be faster to save the .csv files that I generate to an Amazon S3 bucket. I have already set one up. I just dont know how to do it from R studio. </p>
  
  <p>I have been able to access my S3 bucket with SQL Workbench with the code:</p>
  
  <pre><code>UNLOAD
  ('SELECT * FROM rawdata
  ORDER BY timestamp')
  TO 's3://data-**-**/file_name'
  credentials '***'
  delimiter ','
  PARALLEL OFF
  GZIP;
  </code></pre>
  
  <p>but I would like to do a similar function in Rstudio (Version 0.98.109). Does anyone have example code for this perhaps with a sample SQL query? I could run it in SQL workbench but I have the SQl queries embedded in other code that I prefer to run in Rstudio.</p>
  
  <p>Thanks! </p>