Exporting data as a csv file

I keep getting permission denied when trying to use the write_as_csv code. How do I fix it?

The message that pops up is...

write_as_csv(ALLDATA, "alldata_Yankees.csv")
Error in file(file, ifelse(append, "a", "w"), encoding = fileEncoding) :
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w"), encoding = fileEncoding) :
cannot open file 'alldata_Yankees.csv': Permission denied

Any chance that all_data_Yankees.csv is currently open? If you change the filename do you get the same error?

Would it help to include the full path, eg, "C:/myprojects/all_data_Yankees.csv"