0

I found a way to use cmd to add a header record to a file:

@echo off    
echo group  id  firstname   lastname   homephone > new.csv
type old.csv >> new.csv

I want to run this in R using system(), but I get a status code 127 error.

How can I get this command to run?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Pablo Boswell
  • 805
  • 3
  • 13
  • 30
  • Why not just use R for this? (i.e. no `system()` / `system2()`) Also, you have no commas in your `echo` but seem to claim this is a CSV file. – hrbrmstr Nov 30 '18 at 18:47
  • I literally copied this from another StackOverflow question...they used .csv, but I tried with "," and didn't work. The issue is that this is a 16GB file, and it makes no sense to load into R to then rewrite it out. I am looking to use native OS efficiency. – Pablo Boswell Nov 30 '18 at 18:51
  • O_o Um… `stringi::stri_read_lines` is as fast or faster than Windows `type`; facts matter. And "it makes sense to spawn a new process but not use R without that extra bit of work" is also kind of weird to say. But, good luck to you. – hrbrmstr Nov 30 '18 at 18:55
  • To add context, we have a dynamic system that uses R in loops for other components of the process, so if R could then execute system commands, it would help. I also run into a memory issue within R, and am hoping the system command wouldn't. I could be wrong...I am trying to learn – Pablo Boswell Nov 30 '18 at 19:00
  • Also, take a look at the 2nd answer https://stackoverflow.com/questions/41982238/add-header-to-csv-without-loading-csv – Pablo Boswell Nov 30 '18 at 19:01
  • a) according to R docs, stri_read_lines is an "experimental function" b) according to the interwebs, stri_read_lines cannot handle large datasets as well as readLines or fread – Pablo Boswell Nov 30 '18 at 19:27
  • Well, it's used in production in thousands or orgs; it can handle large datasets provided you've got the RAM; `readLines()` is slow and horribad; `fread` is for CSV files not straight line reading. And, i'm officially done with this q. Again, good luck to you. – hrbrmstr Nov 30 '18 at 19:30

0 Answers0