[Rd] Feature Request: Allow Underscore Separated Numbers

@vi@e@gross m@iii@g oii gm@ii@com @vi@e@gross m@iii@g oii gm@ii@com
Fri Jul 15 02:21:38 CEST 2022


I cannot say anyone wants to tweak R after the fact to accept numeric items
with underscores as that might impact all kinds of places.

Can I suggest a workaround that allows you to enter your integer (or
floating point which gets truncated) using this:

underint <- function(text) as.integer(gsub("_+", "", text))

Use a call to that anywhere you want an int like:

result <- underint("1_000_000") + underint("6___6__6_6") - 6000

results in: 100666

If you want to see the result with underscores, using something like
scales::comma as in

You can also make similar functions that use as.numeric() and as.double()
but note that this allows you to enter data at somewhat greater expense and
as text/strings. Obviously a similar technique can be used with regular
expressions of many kinds to wipe out or replace anything, including commas
with this:

undernumeric <- function(text) as.numeric(gsub("[,_]+", "", text))

[1] 123456.8

Yes, it truncated it but I am sure any combo of underscores and commas will
be removed. It also truncates the same thing with all numerals and a period.

-----Original Message-----
From: R-devel <r-devel-bounces using r-project.org> On Behalf Of Devin Marlin
Sent: Thursday, July 14, 2022 3:54 PM
To: r-devel using r-project.org
Subject: [Rd] Feature Request: Allow Underscore Separated Numbers


After using R for a number of years, and venturing into other languages,
I've noticed the ones with the ability to enter numbers separated by
underscores for readability (like 100000 as 100_000) make life a whole lot
easier, especially when debugging. Is this a feature that could be
implemented in R?


*Devin Marlin*

	[[alternative HTML version deleted]]

R-devel using r-project.org mailing list

More information about the R-devel mailing list