R Warning message: In scan(file… : embedded nul(s) found in input

 

In this R tutorial you’ll learn how to deal with the “Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input”.

Table of contents:

Let’s take a look at some R codes in action!

 

Example 1: Reproduce the Warning Message in scan : embedded nul(s) found in input

This section explains how to replicate the “Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input” in the R programming language.

Let’s assume that we want to read a CSV file into R. Then, we might try to import the file using the read.csv function.

Have a look at the following R code:

read.csv("my_data.csv") # Try to import CSV file
# Warning message:
#   In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input

Unfortunately, the execution of the previous R code leads to the “Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input”.

The reason for this warning message is typically the file encoding of the CSV file we are trying to import.

So how can we solve this problem?

 

Example 2: Fix the Warning Message in scan : embedded nul(s) found in input

In Example 2, I’ll explain how to handle the “Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input”.

To avoid this warning message, we have to find the correct encoding of our input file, and we have to specify this encoding type to the fileEncoding argument of the read.csv function.

Let’s assume that the correct encoding of our input file is “UTF-16LE”. Then, we could load our CSV file without the warning message as shown below:

read.csv("my_data.csv", # Specify encoding of CSV file
          fileEncoding = "UTF-16LE")

In case you don’t know the correct encoding of your CSV file, you may have a look at this article. It explains different types of encoding in some more detail.

 

Video, Further Resources & Summary

I have recently released a video on the Statistics Globe YouTube channel, which shows the R codes of this tutorial. You can find the video below:

 

The YouTube video will be added soon.

 

Furthermore, you could have a look at the other articles on my website:

 

In summary: This article has shown how to avoid the “Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input” in the R programming language. If you have additional questions or comments, please let me know in the comments section below.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu
Top