read_csv unexpected '=' syntax error

New to Rstudio.

I open a csv file and change one column from char to 'date'

Then click Import and it works fine. However, if I try to put this in a script to avoid changing to date every time I open this, the code preview I use does not work.

The error is this:
Error: unexpected '=' in:
"SampleImport <- read_csv("LoadingData/data/SampleImport.csv",
+ col_types ="

I try to make sense of the Help file, but I don't recognize my error there.

Hi @cortaz8,

In addition to providing the error message, you should also provide the code you ran that produced this error. This will help when trying to diagnose the issue.

Hi @mattwarkentin,

My mistake ! I forgot to paste the code. It goes like this:

SampleImport <- read_csv("LoadingData/data/SampleImport.csv",
+ col_types = cols(HireDate = col_date(format = "%m/%d/%Y")))

No problem. I don't have your data so I can't confirm whether this fix will work, but you have a + in the code that you don't need:

SampleImport <- read_csv("LoadingData/data/SampleImport.csv",
  col_types = cols(HireDate = col_date(format = "%m/%d/%Y")))

Try the above code.

1 Like

Thank you very much. It worked!

I had pasted the code with the '+' sign from the import window.

I will have to learn how to decipher these. Not obvious for a beginner.

Thanks again.

If you are using RStudio, I recommend copying and pasting previously run commands from the History pane, rather than from the Console. This will avoid any + from sneaking into your code.