Reputation: 1
I wasted a lot of time for reading about R encoding hell, but unfortunately didnt find decision.
I need in R to assign character var with "ñ" symbol
utm <- "españa"
And after this pass this var as argument to google api function
pvs <- google_analytics_4(id,
date_range = c(date - 7, date - 1),
metrics = "pageviews",
dimensions = "countryIsoCode",
dim_filters = filter_clause_ga4(list(dim_filter("source", "EXACT", utm))))
But R/R Studio/Windows (I dont know what) read "españa" as "espana" and pass it to google_analytics_4() argument and as result GoogleAPI dont return any data, because "espana" utm-tag doesnt use. I read about set Sys.getlocale and Sys.setlocale and anothers things, but dont find how fix it.
So what is the easiest way to pass exactly "españa" rather "espana".
P.S.
> sessionInfo()
R version 3.4.0 (2017-04-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale: [1] LC_COLLATE=Russian_Russia.1251 LC_CTYPE=Russian_Russia.1251 LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C LC_TIME=Russian_Russia.1251
attached base packages: [1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached): [1] compiler_3.4.0 tools_3.4.0
Upvotes: 0
Views: 99
Reputation: 2832
Since you haven't posted your session info, the best suggestion I can give is that you use charToRaw("ñ")
. This will return a code, something like c3 b1
. It's usually the second one you use, along with \u00
.
For example, on my Mac, getting the character Ã
, I can use something like:
> print("\u00c3")
[1] "Ã"
You can assign this code as part of utm
:
utm <- "espa\u00b1a`.
Keep in mind this works on my computer, with my settings. As R Yoda mentioned in the comments, you'll need to check on your own machine.
Upvotes: 0