R Warning Message in read.table: Incomplete Final Line Found by readTableHeader

 

In this article, I’ll show how to deal with the read.table warning message “incomplete final line found by readTableHeader” in the R programming language.

The article will consist of the following:

Let’s do this:

 

Example 1: Reproduce the Warning Message in read.table: incomplete final line found by readTableHeader

The R code below illustrates how to replicate the warning message “incomplete final line found by readTableHeader” that is sometimes returned by the read.table function.

Let’s assume that we want to load the data shown in Figure 1 as txt-file into R:

 

r warning incomplete final line found by readTableHeader

 

Then, we would usually use the read.table function as shown below:

read.table("C:/Users/Joach/Desktop/My Folder/my_data.txt",             # txt file without bottom line
           header = TRUE)
# Warning message:
# In read.table("C:/Users/Joach/Desktop/My Folder/my_data.txt", header = TRUE) :
#   incomplete final line found by readTableHeader on 'C:/Users/Joach/Desktop/My Folder/my_data.txt'

As you can see the previous R syntax leads to the warning message “incomplete final line found by readTableHeader”. The reason for this is that our txt-file does not contain a blank line at the bottom.

Next, I’ll show how to fix this problem.

 

Example 2: Fix the Warning Message in read.table: incomplete final line found by readTableHeader

In Example 2, I’ll explain how to avoid the warning message “incomplete final line found by readTableHeader”.

For this, we have to add a newline at the bottom of our txt-file (i.e. “\n”). We can do that by simply pressing the return button at the very end of our data file, leading to the following txt-file:

 

read.table warning incomplete line R

 

Now, let’s run the read.table function once again:

read.table("C:/Users/Joach/Desktop/My Folder/my_data_final_line.txt",  # txt file with empty bottom line
           header = TRUE)
#   x1 x2 x3
# 1  1  5  9
# 2  2  5  8
# 3  3  5  7

The warning message disappeared and the output looks fine!

 

Video & Further Resources

Would you like to learn more about warning messages in R? Then you could watch the following video of my YouTube channel. I’m explaining the R code of this article in the video.

 

The YouTube video will be added soon.

 

In addition, you could read the other tutorials of this homepage:

 

You learned on this page how to handle the warning “incomplete final line found by readTableHeader” in the R programming language. If you have any further questions, don’t hesitate to tell me about it in the comments below.

 

Subscribe to my free statistics 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. Required fields are marked *

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

Menu
Top