Skip to content

Commit

Permalink
include SO metric
Browse files Browse the repository at this point in the history
  • Loading branch information
hfrick committed May 26, 2017
1 parent 080ca26 commit bb721ac
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 49 deletions.
45 changes: 24 additions & 21 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
Package: packagemetrics
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "[email protected]", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.4.0)
Imports:
dplyr,
tidyr,
purrr,
stringr,
rvest,
cranlogs,
janitor,
tidyverse,
xml2,
devtools
License: MIT
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Package: packagemetrics
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "[email protected]", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.4.0)
Imports:
dplyr,
tidyr,
purrr,
stringr,
rvest,
cranlogs,
janitor,
tidyverse,
xml2,
devtools,
stackr,
tidytext,
tibble
License: MIT
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
15 changes: 9 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(cran_metrics)
export(getGitHub)
export(scrape_github_package_page)
importFrom(dplyr,"%>%")
# Generated by roxygen2: do not edit by hand

export(combine_metrics)
export(cran_metrics)
export(getGitHub)
export(get_pkgs)
export(scrape_github_package_page)
export(so_metrics)
importFrom(dplyr,"%>%")
5 changes: 4 additions & 1 deletion R/combine_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
combine_metrics <- function(package_name) {
c_pkg <- cran_metrics(package_name)
git_pkg <- scrape_github_package_page(package_name)
dplyr::full_join(c_pkg, git_pkg, by="package")
so_pkg <- so_metrics(package_name)
res <- dplyr::full_join(c_pkg, git_pkg, by = "package")
res <- dplyr::full_join(res, so_pkg, by = "package")
return(res)
}


7 changes: 2 additions & 5 deletions R/cran_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#' cran_metrics("dplyr")

cran_metrics <- function(package_name) {
tv_packages <- c("broom", "dplyr", "forcats", "ggplot2", "haven", "httr", "hms",
"jsonlite", "lubridate", "magrittr", "modelr", "purrr", "readr", "readxl",
"stringr", "tibble", "rvest", "tidyr", "xml2", "tidyverse")
cran %>%
dplyr::filter(package %in% package_name) %>%
dplyr::select(package, author,
Expand All @@ -27,7 +24,7 @@ cran_metrics <- function(package_name) {
dplyr::mutate(
author_new = purrr::map(author, ~gsub("aut, cre", "", .)),
author_count = purrr::map(author_new, count_packages), #number of authors
tidyverse_happy = ifelse(stringr::str_detect(imports, paste(tv_packages, collapse="|")), 1, 0),
tidyverse_happy = ifelse(stringr::str_detect(imports, paste(tidyverse::tidyverse_packages(), collapse="|")), 1, 0),
has_vignette_build = ifelse(is.na(vignettebuilder), 1, 0)
) %>%
dplyr::select(-author_new, -(imports:reverse_enhances), -vignettebuilder) %>%
Expand All @@ -42,7 +39,7 @@ count_packages <- function(x){
get_cran_downloads <- function(package_name){
cran_dl_last_day <- cranlogs::cran_downloads(packages = package_name, when = "last-day") %>%
dplyr::rename(dl_last_day = count) %>%
select(package, dl_last_day)
dplyr::select(package, dl_last_day)
cran_dl_last_week <- cranlogs::cran_downloads(packages = package_name, when = "last-week") %>%
dplyr::summarise(dl_last_week = sum(count))
cran_dl_last_month <- cranlogs::cran_downloads(packages = package_name, when = "last-month") %>%
Expand Down
Binary file added inst/sandbox/results_table.rda
Binary file not shown.
86 changes: 86 additions & 0 deletions inst/sandbox/so_h2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# install.packages("devtools")
devtools::install_github("dgrtwo/stackr")

library("stackr")

Sys.setenv(STACK_EXCHANGE_KEY = "5Ib89*ZRQgg2kKogWgS3)g((")


## get # hits for a given pkg
hits <- function(pkg, sotag = "r", pagesize = 100, num_pages = 200, ...){
res <- stack_search(body = pkg, tagged = sotag, pagesize = pagesize,
num_pages = num_pages, ...)
nrow(res)
}

foobar <- hits(pkg = "trackeR")
foo <- stack_search(body = "trackeR", tagged = "r", pagesize = 100, num_pages = 200)


















## get questions with [r] tag and "table" in the body
results <- stack_search(tagged = "r", body = "table", filter = "withbody",
pagesize = 100, num_pages = 200)
save(results, file = "results_table.rda")
names(results)
results[1,"body"]


library("tidytext")
body <- results[, "body", drop = FALSE]
str(body)

tidyResults <- body %>% unnest_tokens(output = word, input = body, token = "words")
str(tidyResults)
head(tidyResults, 20)
foo <- tidyResults %>% anti_join(stop_words)
head(foo, 20) ## hu?

availPkg <- available.packages(repos="https://cran.rstudio.com")
class(availPkg)

library("tibble")
apkg <- as.tibble(availPkg)

fooInner <- tidyResults %>% inner_join(select(apkg, Package), by = c("word" = "Package"))
head(fooInner)
fooSemi<- tidyResults %>% semi_join(select(apkg, Package), by = c("word" = "Package"))
head(fooSemi)



###--------------------------------
## get df with posts with "table" in the title
posts <- stack_search(intitle = "table")

names(posts)
head(posts)

## get more info on those questions

qs <- stack_questions(id = posts$question_id)

names(qs)
head(qs)

as <- stack_questions(id = posts$question_id, special = "answers")

names(as)
head(as)

##---
22 changes: 22 additions & 0 deletions man/combine_metrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/get_hits.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions man/get_pkgs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/so_metrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions packagemetrics.Rproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
Encoding: UTF-8

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

0 comments on commit bb721ac

Please sign in to comment.