source(file.path(usethis::proj_get(), "vignettes", "_common.R"))
github.observatory
by using:install.packages("remotes") remotes::install_github("harell/github.observatory")
Sys.setenv( AWS_ACCESS_KEY_ID = "<your-access-key-id>", AWS_SECRET_ACCESS_KEY= "<your-secret>", AWS_REGION = "ap-southeast-2" )
github.observatory
gives easy access to the project database through a Repository object named Ecosystem. To access the database, instantiate a Ecosystem object.ecos <- Ecosystem$new()
agent <- Agent$new(ecos)
dplyr
.user_login
this is a mutable name of the Github account chosen by the User. It is apparent in the Github URL. For example, https://github.com/harell corresponds to user_login
= harell
; anduser_id
this is an immutable number assign by Github when the User creates an account. user_id
is not readily available and has to be deduced from an API call. For example, user_id
= 7226303
, corresponds to user_login
= harell
, and the respective API call is https://api.github.com/user/7226303.message("Among the two options to identify a **User**, `user_id` is preferable as it stays the same throughout the life of GitHub. See the *Mapping Entities* section for how to locate `user_id` with `user_login`.")
invisible( available_tables <- ls(ecos, sorted = FALSE) |> setdiff(c("finalize", "initialize")) |> purrr::keep(~stringr::str_detect(.x, "^read_")) |> stringr::str_remove("^read_") ) print_tables <- function() glue::glue_collapse( paste0("`", available_tables, "`"), sep = ", ", last = " and " )
The Ecosystem gives access to r print_tables()
tables.
message("See the tables content at the Appendix")
user_id
to user_login
Finding a user_id
with user_login
user_login <- "harell" ( user_id <- ecos$read_USER() |> dplyr::filter(login %in% user_login) |> dplyr::pull(id) )
package
(CRAN package name) to repo_id
cran_package <- "dplyr" ( repo_id <- ecos$read_REPO() |> dplyr::filter(package %in% cran_package) |> dplyr::pull(id) )
The Recommendation Agent has five functions:
recommend_repos_to_user
Given a user_id
suggests n
repos the user might like;recommend_users_to_user
Given a user_id
suggests n
users the user might like;query_repos_graph
Given a repo_id
and a method
, find all linked packages in degrees
degrees of separation;query_users_graph
Given a user_id
and a method
, find all linked users in degrees
degrees of separation; andquery_package_stats
Given a CRAN package
name, and a particular statistic
(a function of the data sample), return the value of the requested attribute.Agent
help file for supported methods)suggested_repos <- agent$recommend_repos_to_user(user_id, n = 5, method = "random") print(suggested_repos)
( suggested_repos |> dplyr::left_join(ecos$read_REPO(), by = c("repo_id" = "id")) )
Agent
help file for supported methods)suggested_users <- agent$recommend_users_to_user(user_id, n = 5, method = "random") print(suggested_users)
( suggested_users |> dplyr::left_join(ecos$read_USER(), by = c("user_id" = "id")) )
To query the repo graph, you need to supply three input arguments:
repo_id
: See Mapping Entities for how to map a package name to repo_id);degree
: How many neighbourhood to retrieve?method
: Either depends
or reverse depends
depends
returns the package dependencies (as appears in its DESCRIPTION file);reverse depends
returns packages that are dependent on repo_id
.repo_dep <- agent$query_repos_graph(repo_id, degrees = 1, method = "depends") print(repo_dep)
( repo_dep |> dplyr::left_join(ecos$read_REPO(), by = c("to" = "id")) )
repo_rev_dep <- agent$query_repos_graph(repo_id, degrees = 1, method = "reverse") print(repo_rev_dep)
( repo_rev_dep |> dplyr::left_join(ecos$read_REPO(), by = c("from" = "id")) )
To query the repo graph, you need to supply three input arguments:
repo_id
: See Mapping Entities for how to map a package name to repo_id);degree
: How many neighbourhood to retrieve?method
: Either followers
or following
followers
What users are following user_id
?; orfollowing
What users is user_id
following?user_id
user_followers <- agent$query_users_graph(user_id, degrees = 1, method = "followers") print(user_followers)
user_id
followers( user_followers |> dplyr::left_join(ecos$read_USER(), by = c("from" = "id")) )
user_id
following user_following <- agent$query_users_graph(user_id, degrees = 1, method = "following") print(user_following)
user_id
is following( user_following |> dplyr::left_join(ecos$read_USER(), by = c("to" = "id")) )
dplyr
was downloaded every monthpackage_downloads <- agent$query_package_stats("dplyr", statistic = "monthly downloads") package_downloads |> tail(n = 12) |> print()
plot( package_downloads$date, package_downloads$downloads, main = "Monthly downloads of `dplyr` from RStudio CRAN mirror", type = "b", xlab = "Date", ylab = "Monthly Downloads" )
knitr::include_graphics("https://imgur.com/i6eN9td.png")
for(tbl_name in available_tables){ cat("\n\n##", tbl_name,"\n") invisible( ecos[[paste0("read_", tbl_name)]]() |> dplyr::glimpse() ) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.