0

I'm trying to upload a GSS data set into R Markdown for creating a lecture presentation.

Each time I do, I get errors that I do not understand. Any help would be appreciated.

read.csv("directory/GSS2018.xls", headers = TRUE)

Error in read.table(file = file, header = header, sep = sep, quote = quote, : unused argument (headers = TRUE)

My .xls has headers, so I'm not sure why it is saying "untrue". Even still, I tried taking out the headers option and received this:

read.csv("~directory/GSS2018.xls")

line 1 appears to contain embedded nullsline 2 appears to contain embedded nullsline 3 appears to contain embedded nullsline 4 appears to contain embedded nullsline 5 appears to contain embedded nullsError in make.names(col.names, unique = TRUE) : invalid multibyte string at '<1a>'

I can't quite get what this error is telling me, nor how to fix it. I can import my data just fine using the "Import Dataset" button on the environment sector of R Studio - but when I put that code into R markdown, it shows up all these errors.

Any help is appreciated!

Dave2e
  • 22,192
  • 18
  • 42
  • 50
  • 1
    Try with `header=TRUE` instead of headers. – stefan Feb 01 '21 at 18:52
  • Thanks Stefan - the same problem appears from the second attempt when I say "header". > read.csv("~/directory/GSS2018.xls", header=TRUE) line 1 appears to contain embedded nullsline 2 appears to contain embedded nullsline 3 appears to contain embedded nullsline 4 appears to contain embedded nullsline 5 appears to contain embedded nullsError in make.names(col.names, unique = TRUE) : invalid multibyte string at '<1a>' – Erik Lovell Feb 01 '21 at 18:57
  • Hi Erik. Have a look at this post https://stackoverflow.com/questions/23209464/get-embedded-nuls-found-in-input-when-reading-a-csv-using-read-csv or https://stackoverflow.com/questions/24734911/warning-message-line-appears-to-contain-embedded-nulls. – stefan Feb 01 '21 at 19:07
  • Are you trying to open a CSV file or an Excel file? The file extension is implying an Excel file, in which you should use the "readxl" package. – Dave2e Feb 01 '21 at 22:51
  • Hi Dave - I've used both (with both the readxl and read.csv). – Erik Lovell Feb 02 '21 at 14:56
  • Judging by the file's extension, I suggest trying `readxl::read_excel()` function, but without seeing the file it is just a guess. – Dave2e Feb 03 '21 at 23:39

0 Answers0