R code to split big table into smaller .txt files and save to computer?
<p>I have a huge .txt file named SDN_1 with more than 1 million rows. I would like to split this file into smaller .txt files (10,000 rows each) using R. </p>

<p>I used this code to load the file into R:</p>

<pre><code>SDN_1 &lt;- read.csv("C:/Users/JHU/Desktop/rfiles/SDN_1.csv", header=FALSE)
</code></pre>

<p>Then I used this code to split the table:</p>

<pre><code>chunk &lt;- 10000
n     &lt;- nrow(SDN_1)
r     &lt;- rep(1:ceiling(n/chunk),each=chunk)[1:n]
d     &lt;- split(SDN_1,r)
</code></pre>

<p>Next I would like to save the output of the split function into separate files as .txt and encode as UTF8. The files need to be named in the following format: test_YYYMMDD_HHMMSS.txt</p>

<p>I'm new to R and any help would be appreciated.</p>

<p>UPDATE:
Hack-R suggested the code below to create the .csv file. The code below worked once then started giving me the error message below:</p>

<p>Code Hack-R suggested:</p>

<pre><code>n &lt;- 1
for(i in d){
con &lt;- file(paste0("file",n,"_", gsub("-
","",gsub(":","",gsub("","_",Sys.time()))), "_",".csv"),encoding="UTF-8")
write.csv(tmp, file = con)
n &lt;- n + 1
}
</code></pre>

<p>The error message I'm getting:</p>

<pre><code>Error in is.data.frame(x) : object 'tmp' not found 
</code></pre>