This is a bit silly. Anyone who wants to type less has many trivial ways to do so by themselves. And, why call it "span" when something like "a1" is even shorter! LOL!
You can choose to shorten even many built-ins for many purposes and perhaps make your programs a tad of a challenge to read. You can put code like this once in your program (or any other file you include or even in your R-startup file) and use it as often as you wish: span <- function(details) { max(details) - min(details) } Of course, if you only use it ONCE, then just typing in a one-liner works. If everyone asked for their favorite little function to be added to the base, we might have some serious namespace issues and other concerns. Consider a function like read.table() which is fairly standard and takes LOTS of arguments with some defaults. It can be configured to read in lots of things but often it is used in a way, such as reading .CSV files, where other defaults would make sense, such as using a comma as a separator. So, to make life easier and less typing or mistakes, many people call read.csv() which results in an indirect call to read.table() with some new defaults set or over-ridden: > read.csv function (file, header = TRUE, sep = ",", quote = "\"", dec = ".", fill = TRUE, comment.char = "", ...) read.table(file = file, header = header, sep = sep, quote = quote, dec = dec, fill = fill, comment.char = comment.char, ...) For convenience there is also a read.delim and a second version of each as in read.csv2. BUT you can make your own functions trivially that ultimately call read.table along with any pre or post processing you want a wrapper like this to do. The request by Dr. Fisher is for a fairly minor thing, that can be handled easily enough BUT I note with care. Presumably, a better design for a function would make sure to check if the arguments to the function made sense. Arguably both need to be numeric or something where a subtraction makes sense. It probably is not expected to work for character strings but might work, sort of, for certain kinds of dates: > a <- as.Date("2025-12-15") > b <- as.Date("2025-12-22") > b - a Time difference of 7 days > span(c(a, b)) Time difference of 7 days > span(c(a, b)) + 1 Time difference of 8 days A good design might decide what errors to trap and what to return. For example, do you handle an NA, or all NA, not to mention NaN and Inf, or two incompatible types. To build something into base R might be a bit more complex that what you might throw in for yourself or in some package and may even be written not in base R but some C variant. There are MANY places in R people wish something had been done, or done differently, and few are considered worthy enough when some simple method exists that can be done in a line or two of code. -----Original Message----- From: R-help <r-help-boun...@r-project.org> On Behalf Of Dennis Fisher Sent: Wednesday, June 25, 2025 3:35 PM To: Ebert,Timothy Aaron <teb...@ufl.edu> Cc: r-help <r-help@r-project.org> Subject: Re: [R] Does this exist: diff(range(VAR, na.rm=T)) you are missing the point: span(…) requires less typing than diff(range(….)) just like paste0 simplifies use of the paste command Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-415-307-4791 www.PLessThan.com > On Jun 25, 2025, at 12:32 PM, Ebert,Timothy Aaron <teb...@ufl.edu> wrote: > > I do not see the problem. > In base R > Min <- min(var, na.rm=T) > Max <- max(var, na.rm=T) > Span <- c(Min, Max) > > Is the same output as > Span <- range(var, na.rm=T) > > diff(range(var, na.rm=T)) returns Max - Min > > range() returns a vector with two values, the minimum and the maximum. > What should the function "span" do that is not already done? > > Tim > > -----Original Message----- > From: R-help <r-help-boun...@r-project.org > <mailto:r-help-boun...@r-project.org>> On Behalf Of Dennis Fisher > Sent: Wednesday, June 25, 2025 2:11 PM > To: r-help <r-help@r-project.org <mailto:r-help@r-project.org>> > Subject: [R] Does this exist: diff(range(VAR, na.rm=T)) > > [External Email] > > Version 4.4.2 > OS X > > Colleagues > > I often need to determine the span of the x-variable in a graphic. > > This is easy to determine with: > diff(range(VAR, na.rm=T)) > > I am not aware of any function in base R that accomplishes this and "span" is > not taken. > > Would it be possible to add such a function? Not a major addition but often > useful. > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone: 1-415-307-4791 > http://www.plessthan.com/ > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To > UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.r-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.