klmr,
@klmr@mastodon.social avatar

WTF of the day:

gaborcsardi,
@gaborcsardi@fosstodon.org avatar

@klmr

Yeah, you can have a string literal on the LHS, to assign values to non-syntactic names, I think that's from before we had backticks.

How the symbol name changes to NA is more surprising to me, maybe this is a bug:
❯ as.symbol(NA_character_)
NA

I think R should just not allow an NA string literal on the LHS of an assignment. It should probably be an error.

klmr,
@klmr@mastodon.social avatar

@gaborcsardi I think R should not allow string literals in place of names, full stop. This change is even worth breaking a few packages on CRAN, IMHO, because the current behaviour is plain bananas and causes plenty of confusion.

gaborcsardi,
@gaborcsardi@fosstodon.org avatar

@klmr I have some vague memories that base R replaced the string literal symbols with backticks a long time ago,.

IDK if CRAN ever looked at the amount of breakage it would cause to make this an error.

klmr,
@klmr@mastodon.social avatar

@gaborcsardi Yes, backticks came later. And there’s still some ancient core R code which uses "-quoted names, but that could obviously be fixed when deprecating/removing the syntax. But I don’t think there’s appetite for it.

klmr,
@klmr@mastodon.social avatar

… but:

» NA_character_
[1] NA
» NA_character_
Error: object 'NA_character_' not found

Elendol,
@Elendol@hachyderm.io avatar

@klmr is it because NA_character_ only the representation of NA for print and not the actual value?

klmr,
@klmr@mastodon.social avatar

@Elendol Yes, and because R allows character literals instead of syntactic names in some places, including as the LHS of assignments. 🤮

Elendol,
@Elendol@hachyderm.io avatar

@klmr oh no 😢

hrbrmstr,
@hrbrmstr@mastodon.social avatar

@Elendol @klmr technically, NA_character_ is a reserved word https://stat.ethz.ch/R-manual/R-devel/library/base/html/Reserved.html

Reserved words are oddly allowed as non-syntactic names.

NA_character_ kind of only exists b/c comparisons (and NA values) in R vectors need to be typed; albeit in this kind of hacky way.

klmr,
@klmr@mastodon.social avatar

@hrbrmstr But it only works with NA_character_, not NA, NA_real_, TRUE or any other reserved names. — And the reason is that NA_character_ (unlike all the others) is a character literal.

» NA = 1
Error in NA = 1 : invalid (do_set) left-hand side to assignment

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines