'Unable to export r file

the error message I get is as follow...

Error in file(file, ifelse(append, "a", "w")) : cannot open the connection
6. file(file, ifelse(append, "a", "w"))
5. utils::write.table(counts, file = "~/Desktop/tripdata/Casestudy", col.names = NA, sep = ",", dec = ".", qmethod = "double")
4. eval(expr, p)
3. eval(expr, p)
2. eval.parent(Call)
1. write.csv(counts, file = "~/Desktop/tripdata/Casestudy")

and my code is...

counts <- aggregate(all_trips_v2$ride_length ~ all_trips_v2$member_casual + all_trips_v2$day_of_week, FUN = mean)

write.csv(counts, file = '\~/Desktop/tripdata/Casestudy')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source