Closed McCartneyAC closed 2 years ago
slightly more effective:
library(rvest)
url<-"http://www.nationsonline.org/oneworld/country_code_list.htm"
xpath<-"//*[@id="codelist"]"
country_codes<-url %>%
read_html() %>%
html_nodes(xpath='//*[@id="codelist"]') %>%
html_table() %>%
as.data.frame() %>%
as_tibble() %>%
select(Country.or.Area.Name, ISO..ALPHA.2.Code) %>%
rename("name" = "Country.or.Area.Name" ,
"code" = "ISO..ALPHA.2.Code" )
Hi there! You're right: they aren't currently included as structured data that is usable by the user. The codes use the two letter ISO 3166-1 alpha-2 standard, and I'd recomend using the countrycode
package to get them from your present data. (I should definitely write a vignette for this!)
That said, if you do need to specifically access the data used by this package, it's essentially a list of SVG files named by code:
library(ggflags)
data(lflags)
.flaglist # WARNING: straight-up printing this will not be fun
names(.flaglist) . # the country codes
I'd love to switch this to use a data frame with a list column so they could be properly exposed to the user, but there're a couple of rendering bugs that probably need to be fixed first.
Thanks! I can't tell you how excited I am to be able to use this package--I've been trying to get ggemoji and emo::ji to work for ages not knowing this existed.
No worries! @baptiste got it going, and I started working on it for a project of my own (though I've now moved on to using D3, so my immediate use case has expired 😅).
As much as I love ggemoji and emo::ji packages, emoji support across platforms and devices is kind of a disaster, so I think using images—or, ideally, vector files like SVG—is the way to go for emoji. Once I cross the immediate to-dos off this package's buglist, I'd like to make a new package that handles arbitrary user-supplied sets of SVG icons.
But I can't seem to see if/where country code data are included in the package as structured data that can be used, so you might include this code in the vignette/main package examples page for people:
but if they're already there and I didn't look hard enough, I apologize!