0

I am not sure what's wrong with my R query.

Here is the warning message in a list:

https://drive.google.com/file/d/13KK_gIiI_T7l1IezhsNXG0asiMatU9wz/view?usp=sharing

My R code is to get, for example, the "AACQW" from "x = AACQW".

library(tidyverse)
str_extract_all(warnings, "x\\s=\\s.+\\"")

Thanks for any help!

Steve
  • 193
  • 8

1 Answers1

0

Those values are present in the names of warnings. Try :

trimws(stringr::str_extract(names(warnings), "(?<=x\\s=\\s)'\\w+'"), whitespace = "'")

#[1] "AACQW" "AACQW" NA      NA      NA      "ACAHU" "ACAHU" NA      NA     
#[10] NA      "ACEVW" "ACEVW" NA      NA      NA      "ACKIW" "ACKIW" NA     
#[19] NA      NA      "ADILW" "ADILW" NA      NA      NA      "ADNWW" "ADNWW"
#[28] "ADOCR" "ADOCR" "ADOCW" "ADOCW" "ADVWW" "ADVWW" NA      NA      NA     
#[37] "AGBAR" "AGBAR" "AGBAW" "AGBAW" NA      NA      NA      NA      NA     
#[46] NA      "AHACW" "AHACW" NA      NA  

I used trimws to remove '' around the names.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Can you teach me why you use regex lookbehind, instead of lookforward? Isn't it the "x = " I should be searching for first, and then (lookforward to) gobble up the uppercase letters that follow? – Steve Mar 07 '21 at 06:00
  • Yes, so we are looking for `x = ''` and extracting a word after that. `?<=` is the look behind part. This link is an excellent resource to understand lookbehind and lookahead regex https://stackoverflow.com/questions/2973436/regex-lookahead-lookbehind-and-atomic-groups – Ronak Shah Mar 07 '21 at 07:25