R Warning message : is.na() applied to non-(list or vector) of type ‘closure’

 

In this R tutorial you’ll learn how to replicate and debug the warning message : “is.na() applied to non-(list or vector)”.

Table of contents:

Let’s get started…

 

Example 1: Reproduce the Warning message : is.na() applied to non-(list or vector) of type ‘closure’

In Example 1, I’ll explain how to replicate the warning message : “is.na() applied to non-(list or vector) of type ‘closure'”.

This warning message occurrs when we try to apply the is.na function to another function.

Consider the R code below:

is.na(data)                     # Applying is.na to function
# [1] FALSE
# Warning message:
# In is.na(data) : is.na() applied to non-(list or vector) of type 'closure'

As you have seen, the previous R code has returned the warning message “In is.na(data) : is.na() applied to non-(list or vector) of type ‘closure'”. This is because the name “data” corresponds to the data() function, and not to an actual data set.

Let’s solve this problem…

 

Example 2: Avoid the Warning message : is.na() applied to non-(list or vector) of type ‘closure’

In this example, I’ll demonstrate how to fix the warning message : “is.na() applied to non-(list or vector) of type ‘closure'”.

Let’s first create some example data:

data <- data.frame(x1 = 1:5,    # Create data frame
                   x2 = letters[1:5],
                   x3 = "x")
data                            # Print data frame

 

table 1 data frame r warning message is na applied non list or vector

 

By running the previous R syntax, we have created Table 1, i.e. a data frame object. Note that this data frame object is called “data”, i.e. it has the same name as the data() function.

Next, we can apply exactly the same syntax as in Example 1:

is.na(data)                     # Applying is.na to data frame object

 

table 2 matrix r warning message is na applied non list or vector

 

By executing the previous R programming syntax, we have created Table 2, i.e. a matrix that indicates which values in our data frame are not available (i.e. NA). No warning messages are shown anymore.

The reason for this is that we have defined a new data object called data before using the is.na function. As a result, the is.na function evaluated our data object instead of the data() function.

 

Similar Variations to the is.na() applied to non-(list or vector) Warning Message

The warning message : “is.na() applied to non-(list or vector)” exists in different variants, which depend on the input that is specified within the is.na function. Those variants are:

  • In is.na(NULL) : is.na() applied to non-(list or vector) of type ‘builtin’
  • In is.na(NULL) : is.na() applied to non-(list or vector) of type ‘expression’
  • In is.na(NULL) : is.na() applied to non-(list or vector) of type ‘language’
  • In is.na(NULL) : is.na() applied to non-(list or vector) of type ‘NULL’

In case you want to learn more on these warnings, you may check out this thread on Stack Overflow.

 

Video & Further Resources

Some time ago, I have published a video on my YouTube channel, which explains the examples of this tutorial. You can find the video below.

 

The YouTube video will be added soon.

 

Furthermore, you may read the related articles on my homepage.

 

In this tutorial you have learned how to avoid the warning message : “is.na() applied to non-(list or vector)” in the R programming language. In case you have further questions, please let me know in the comments.

 

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. Required fields are marked *

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

Top