Rosetta Code/Rank languages by popularity: Difference between revisions

(→‎{{header|Wren}}: Wren script largely rewritten to deal with site change.)
Line 4,477:
 
=={{header|R}}==
 
{{incorrect|R|I believe you need to use <tt>continue gcmcontinue</tt> to get complete results.}}
<syntaxhighlight lang="rsplus">
library(rvest)
library(plyr)
library(dplyr)
options(stringsAsFactors=FALSE)
 
# getting the required table from the rosetta website
langUrl <- "http://rosettacode.org/mw/api.php?format=xml&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&prop=categoryinfo&gcmlimit=5000"
langUrl <- "https://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity/Full_list"
langs <- htmlread_html(langUrl) %>%
html_nodes('page')
html_nodes(xpath='/html/body/div/div/div[1]/div[3]/main/div[2]/div[3]/div[1]/table') %>%
html_table() %>%
data.frame() %>%
select(c("Rank","TaskEntries","Language"))
 
 
ff <- function(xml_node) {
# changing the columns to required format
language <- xml_node %>% html_attr("title")
langs$Rank = paste("Rank: ",langs$Rank)
language <- sub("^Category:", "", language)
langs$TaskEntries = paste0("(", format(langs$TaskEntries, big.mark = ",")
npages <- xml_node %>% html_nodes('categoryinfo') %>%
," entries", ")")
html_attr("pages")
 
c(language, npages)
names(langs) <- NULL
}
 
tbl <- ldply(sapply(langs, ff), rbind)
langs[1:10,]
names(tbl) <- c("language", "n")
 
tbl %>%
{{out|Output (as of MarchOctober, 2324, 20192022)}}
mutate(n=as.integer(n)) %>%
arrange(desc(n)) %>%
head
</syntaxhighlight>
{{out|Output (as of March, 23, 2019)}}
<pre>
 
language n
1 Rank: 1 (1,589 Goentries) 1114 Phix
2 Rank: 1 (1,589 entries) Wren
2 Perl 6 1059
3 Rank: 3 (1,552 entries) Julia
3 Kotlin 1029
4 Rank: Phix4 (1,535 993entries) Raku
5 Rank: 5 (1,500 entries) Go
5 Julia 992
6 Rank: Perl6 (1,485 978entries) Perl
7 Rank: 7 (1,422 entries) Python
8 Rank: 8 (1,402 entries) Nim
9 Rank: 9 (1,293 entries) J
10 Rank: 10 (1,213 entries) C
</pre>