Re: [R] Regexp pattern but fixed replacement?

2024-04-11 Thread Duncan Murdoch
On 11/04/2024 12:58 p.m., Iris Simmons wrote: Hi Duncan, I only know about sub() and gsub(). There is no way to have pattern be a regular expression and replacement be a fixed string. Backslash is the only special character in replacement. If you need a reference, see this file: https://g

Re: [R] Regexp pattern but fixed replacement?

2024-04-11 Thread Duncan Murdoch
On 11/04/2024 12:57 p.m., Dave Dixon wrote: Backslashes in regex expressions in R are maddening, but they make sense. R string handling interprets your replacement string "\\" as just one backslash. Your string is received by gsub as "\" - that is, just the control backslash, NOT the character b

Re: [R] Regexp pattern but fixed replacement?

2024-04-11 Thread Iris Simmons
Hi Duncan, I only know about sub() and gsub(). There is no way to have pattern be a regular expression and replacement be a fixed string. Backslash is the only special character in replacement. If you need a reference, see this file: https://github.com/wch/r-source/blob/04650eddd6d844963b6d7aac

Re: [R] Regexp pattern but fixed replacement?

2024-04-11 Thread Dave Dixon
Backslashes in regex expressions in R are maddening, but they make sense. R string handling interprets your replacement string "\\" as just one backslash. Your string is received by gsub as "\" - that is, just the control backslash, NOT the character backslash. gsub is expecting to see \0, \1,

[R] Regexp pattern but fixed replacement?

2024-04-11 Thread Duncan Murdoch
I noticed this issue in stringr::str_replace, but it also affects sub() in base R. If the pattern in a call to one of these needs to be a regular expression, then backslashes in the replacement text are treated specially. For example, gsub("a|b", "\\", "abcdef") gives "def", not "def"

Re: [R] seeking help with splicing in R

2024-04-11 Thread Ebert,Timothy Aaron
Whatever you had as HTML was deleted. If that was data we did not get it. 1) manipulate wpi_def_nic2004 and wpi_def_nic2008 first so that the data are compatible, then join them. 2) The full_join statement should explicitly state the columns to join by. Using by=NULL joins by all the columns with

[R] seeking help with splicing in R

2024-04-11 Thread Manya Budhiraja
Hello! I was trying to splice two wholesale price index deflators series which have different base years. One of them is called wpi_def_nic2004(from 2005 to 2012), and another is called wpi_def_nic2008(from 2012 to 2019). I am trying to create a single series such that the base year prices are con