I am trying to remove all parts of a string beginning with (and including) the word "Footnotes" in the following example but it's not working like I would expect and only deletes characters from that line and not the next one. Any ideas?
The end goal is to remove the footer then use read_csv
to read it in without the footer.
library(stringr)
j <- ",,,\"$75,000 or more\",, 3310, ! , 5224, ! , \r\n,,,\"Unknown\",, 1936, ! , 5369, ! , \r\n\r\n\r\n\r\n\r\nFootnotes:\r\n* Special tabulations from the NCVS Victimization Analysis Tool (NVAT).\r\n\"* Detail may not sum to total due to rounding and/or missing data."
writeLines(j)
#> ,,,"$75,000 or more",, 3310, ! , 5224, ! ,
#> ,,,"Unknown",, 1936, ! , 5369, ! ,
#>
#>
#>
#>
#> Footnotes:
#> * Special tabulations from the NCVS Victimization Analysis Tool (NVAT).
#> "* Detail may not sum to total due to rounding and/or missing data.
# Goal is to remove everything starting with "Footnotes" from j
j2 <- str_replace_all(j, "Footnotes.*", "")
writeLines(j2)
#> ,,,"$75,000 or more",, 3310, ! , 5224, ! ,
#> ,,,"Unknown",, 1936, ! , 5369, ! ,
#>
#>
#>
#>
#>
#> * Special tabulations from the NCVS Victimization Analysis Tool (NVAT).
#> "* Detail may not sum to total due to rounding and/or missing data.
Created on 2020-08-10 by the reprex package (v0.3.0)