0

I've searched a bit for answered questions related to this, but I still keep running into issues.

I have a 1.4 million dataframe loaded into R, containing gps route data for ~56 vehicles. I used the split() function to parse my data into smaller chunks by bus name (Bus name example: '1367/E0007489'). I used the following line of code:

dfs <- split(sater001_paired, f=sater001_paired[, "vehicleName"])

Where sater001_pairedis my dataframe, and vehicleName is the variable I split with. The # of rows for each chunk is uneven, given that this data was captured real-time.

The problem I'm facing now is attempting to save each of these chunks into their own .csv files. I tried using lapply as such:

lapply(names(dfs), function(x){write.table(dfs[[x]], file = paste("bus", x, sep = ""))})

But R returns en error message "cannot open the connection". It's likely I'm missing something, as I'm very rusty on using the lapply function.

Any suggestions based off this?

S_Jenk
  • 13
  • 4
  • Your code works for me... – DatamineR May 17 '16 at 21:54
  • 2
    me too (on a linux box).....have you checked the suggestions on the chosen answer here? http://stackoverflow.com/questions/17156445/why-i-get-this-error-writing-data-to-a-file – joemienko May 17 '16 at 21:59
  • I went through them, and none seem to address my issue as I am an administrator on this workstation, and still repeats the messages ;cannot open connection', as well as an additional 'no such file exist message' – S_Jenk May 17 '16 at 22:18
  • 1
    Are you saying the value you are using for the file names has a slash in it? That's going to cause a problem. You should replace slashes with something else for the file name. It would be more clear if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick May 17 '16 at 22:27
  • The VehicleNames variable that i use as 'names' does have it, in fact. that could be the issue. I'll come back at this he problem and give an update, probably tomorrow. – S_Jenk May 17 '16 at 22:42
  • Are you using rstudio? If so, you may want to try starting it as an administrator. That has solved windows permissions problems for me in the past... – joemienko May 18 '16 at 05:49

1 Answers1

0

MrFlick has helped me realize the issue I was having here.

So just to close this, the Vehicle Names column I had contained a forward slash halfway in each identification code. As Rstudio on windows does not take kindly to these characters, I did not realize this, as I have only recently switched over from primarily Mac OS use.

By using gsub in the following code:

sater001_paired$vehicleName <- gsub('/', '-', sater001_paired$vehicleName)

This issue has now resolved. Thanks again to MrFlick for the help.

S_Jenk
  • 13
  • 4