Home > database >  How to escape # in R
How to escape # in R

Time:04-11

I am reading data with the sf library (https://r-spatial.github.io/sf/reference/st_read.html)

cases <- read_sf(
    dsn = "foo.gpkg",
    query="SELECT \#ID FROM \"foo\""
) 

Which gives me

Error: '#' is an unrecognized escape in character string starting ""SELECT #"

Why does it recognize it as an expace character? I am using \ to escape it.

CodePudding user response:

Just a missing - " - :

cases <- read_sf(
  dsn = "foo.gpkg",
    query="SELECT \#ID FROM \"foo\""
) 

CodePudding user response:

In R, you need double backslashes \\ to escape special character.

cases <- read_sf(
    dsn = "foo.gpkg",
    query="SELECT \\#ID FROM \"foo\""
) 
  •  Tags:  
  • r sf
  • Related