Skip to content

Instantly share code, notes, and snippets.

@agila5
Created May 18, 2021 17:14
Show Gist options
  • Save agila5/573b26b89fe17dc9b7d7eef0771fa19c to your computer and use it in GitHub Desktop.
Save agila5/573b26b89fe17dc9b7d7eef0771fa19c to your computer and use it in GitHub Desktop.
string <- "\"sidewalk\"=>\"none\""
print(string, quote = FALSE)
#> [1] "sidewalk"=>"none"
read.table(
  text = gsub(',?([^,]+)=>',"\n\\1:", string, perl = TRUE), 
  sep = ":", 
  col.names = c("key", "value")
)
#>        key value
#> 1 sidewalk  none
string <- "\"maxwidth\"=>\"6'6\\\"\",\"sidewalk\"=>\"none\""
print(string, quote = FALSE)
#> [1] "maxwidth"=>"6'6\\"","sidewalk"=>"none"
read.table(
  text = gsub(',?([^,]+)=>',"\n\\1:", string, perl = TRUE), 
  sep = ":", 
  col.names = c("key", "value")
)
#> Error in read.table(text = gsub(",?([^,]+)=>", "\n\\1:", string, perl = TRUE), : incomplete final line found by readTableHeader on 'text'

Created on 2021-05-18 by the reprex package (v2.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment