I am running Rstudio on Windows 11 and attempting to read in a local csv file with the read.csv() function, and am running into an error that looks like this:
Warning messages: 1: In read.table(file = file, header = header, sep = sep, quote = quote, :
** line 1 appears to contain embedded nulls** 2: In read.table(file = file, header = header, sep = sep, quote = quote, :
** line 2 appears to contain embedded nulls** 3: In read.table(file = file, header = header, sep = sep, quote = quote, :
** incomplete final line found by readTableHeader**
Putting the file in Google Sheets and Notepad++ displays random ASCII characters. Furthermore, I found out that the encoding of this file is "CP1252"
I appended the argument: encoding="Windows-1252" at the end of the read.csv() function but there was no difference in error result.
Does anyone have any tips or suggestions? Any help would be appreciated.
Try adding the skipNul = TRUE argument to read.csv().
In the long term it would be better to track down the source of the nulls. Check how the CSV file was created?
After adding the skipNul argument, the first two lines of the error codes go away but the "...incomplete final line found by readTableHeader" remains.
> obs_raw <- read.csv("...filepath/observations-July2023_July2024_v2.csv", encoding="Windows-1252", skipNul = TRUE)
Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote, :
incomplete final line found by readTableHeader on '...filepath/observations-July2023_July2024_v2.csv'
>
I found this error code online and it was recommended to add a new line at the end of the document, but that did not change the error either. As for the creation of the CSV, It was downloaded from the iNaturalist research site.
The last message is a Warning, not an Error. The function did complete reading the file. Have you looked at the last row of obs_raw to see if all the data are there?
Hello.
I do see that my obs_raw was created, but it has nonsense information captured in 2 rows (instead of the expected ~100). Here is a screenshot of the table:
I found the {archive} package on CRAN which can help with uncompressing a binary file of unknown source (from help file): "Offers R connections and direct extraction for many archive formats including 'tar', 'ZIP', '7-zip', 'RAR', 'CAB' and compression formats including 'gzip', 'bzip2', 'compress', 'lzma' and 'xz'."
The file was zipped upon download but I was using the unzipped version (using windows built-in unzip function in file explorer).
I just re-downloaded the zipped file and tried unzipping again and it worked... I'm not sure what went wrong in the original process but this time was different.