Fixing R Error: no non-missing arguments to min; returning inf

The non missing arguments error message occurs when a variable that does not have any data is used as an argument in either the maxx or minx function. Fixing the problem is a simple matter of correcting this omission. The exact method will vary with the situation, but the basic principle is still the same. That is making sure that the variable being used has at least one value.

Description of the R error

This error is not a problem with data type coercion, the use of narm to find NA values or using a factor. This message occurs because of an issue with the length of the argument of a function. Unfortunately, while the basic cause of the problem is simple, the situations that cause it can be complicated. This means that finding the solution can sometimes be simple but other times more challenging. Furthermore, it is the more challenging situations where you are most likely to encounter it. This is because the most basic situation is easily avoided, and is not likely to occur by accident.

Explanation of the error

Here is three code examples that show how this error message happens.

> x = c(1, 3, 5 ,7, 9)
> min(x)
[1] 1
> max(x)
[1] 9

This example consists of a number vector that illustrates the proper use of the maxx and minx functions.

> x = numeric(0)
> min(x)
[1] Inf
Warning message:
In min(x) : no non-missing arguments to min; returning Inf
> max(x)
[1] -Inf
Warning message:
In max(x) : no non-missing arguments to max; returning -Inf

This example shows the error message is caused by entering a variable that is an empty vector into the maxx and minx functions.

> plotting = function(y,x,table){
+ x=table$x
+ y=table$y
+ plot(x, y)
+ }
> plotting(speed, dist, cars)
Error in plot.window(…) : need finite ‘xlim’ values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) :
Error in plot.window(…) : need finite ‘xlim’ values

In this situation, we are preparing to plot a dataset. This is a table, not a data frame so its columns cannot be accessed using the dollar sign. This is the problem that triggers the error message. The function is supposed to go through each row and get the value from each column based on the column names. If you fixed only the x value, you would still get our message, but it would reference ‘ylim’ instead of ‘xlim’.

How to fix the R error

Here we have two code examples illustrating how to fix this error message.

> x = c(NA)
> min(x)
[1] NA
> max(x)
[1] NA

In this example, we set the value of the vector that we put through the maxx and minx functions to a missing value. The result is a missing value but no error.

> plotting = function(y,x,table){
+ x=table[,x]
+ y=table[, y]
+ plot(x, y)
+ }
> plotting(“speed”, “dist”, cars)

In this situation, the table is the same but instead, the column names are placed in quotes and access by using brackets rather than the dollar sign. Fixed as illustrated above, the function produces a nice Scatter plot. You can set the axis labels using the xlabel and ylabel functions and draw a line using the lines function. The result is that the problem is fixed and we do not get an error message.

This is an easy-to-understand error message, but it is a challenge to fix because there is no one size fits all solution. The details of how you fix this problem vary depending upon the situation, but once you understand the root cause you can figure out how to fix it in any situation.

Scroll to top