1

Just over a year ago, I searched online for here-document (or similar) capability in R. I didn't find any indication of it. Now, it's among the first things that pop up in a google search -- for example, on Wikipedia. I'm not sure whether this is because it is a relatively new capability, or a capability that was present before but not well-known.

When did this capability became available?

If it was available for much more than a year, was it simply relatively unknown?

(If so, then I was just not searching properly back then).


Code example

In R, one can do

query <-
"
  SELECT FirstName,
         LastName,
         Address
  INTO tAllBobs
  FROM tContacts
  WHERE FirstName = 'Bob'
  ORDER BY LastName
"

In VBA, one has to do:

query = _
  "SELECT FirstName,      " & _
  "       LastName,       " & _
  "       Address         " & _
  "INTO tAllBobs          " & _
  "FROM tContacts         " & _
  "WHERE FirstName = 'Bob' " & _
  "ORDER BY LastName      "

The string delimiters and line continuation syntax makes the code difficult to modify and reformat. Even adding the single quotes around 'Bob' (as I did above) disrupts the formatting. Larger revisions would wreak havoc and require intense re-editing.

This is why I was interested in when here-document capability was supported in R.

user2554330
  • 37,248
  • 4
  • 43
  • 90
user36800
  • 2,019
  • 2
  • 19
  • 34
  • I've been using `read.table(text = "some text")` for years, now learning it is called "here-document". – zx8754 May 05 '21 at 07:56

1 Answers1

2

If you're asking when textConnection was introduced to R, it seems about 21 years ago:

https://github.com/wch/r-source/commit/968826560933840f10919b81a22762c1e7eacee1

Admittedly it's never been easy to search for it -- I only learned it myself in the past 12-18 months, I'd say.

As for Wikipedia, that section has been there since 2012:

https://en.wikipedia.org/w/index.php?title=Here_document&oldid=492468681

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
  • I'm not an R coder, but I was searching for here-document capability as part of a environmental scan of information for a thought piece on data IO practices. I could be wrong, but based on the Wikipedia section cited in my question, it might be more than just `textConnection` (though I did browse the help information for that). I think it may boil down to when `textConnection` started to accept strings. – user36800 May 05 '21 at 06:17
  • Regardless of whether that is the key ingredient, I was also wondering when the here-document capability became well-known. It seems odd that I couldn't find it just over a year ago, but that could just have been either me or a dearth of links to the information online at the time. – user36800 May 05 '21 at 06:17