Skip to content

Commit

Permalink
Merge pull request #41 from massimoaria/for-ropensci
Browse files Browse the repository at this point in the history
Getting ready for ropensci submission
  • Loading branch information
massimoaria authored Nov 8, 2022
2 parents 2ca73fb + d81b0d0 commit c0d32fe
Show file tree
Hide file tree
Showing 28 changed files with 641 additions and 133 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
^vignettes/articles$
^data-raw$
^codecov\.yml$
^dev$
^codemeta\.json$
49 changes: 49 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contributing to openalexR

First, thank you for considering to contribute to openalexR!

This outlines how to propose a change to this package.
For more detailed info about contributing to this, and other tidyverse packages, please see the
[**development contributing guide**](https://rstd.io/tidy-contrib).

## Fixing typos

You can fix typos, spelling mistakes, or grammatical errors in the documentation directly using the GitHub web interface, as long as the changes are made in the _source_ file.
This generally means you'll need to edit [roxygen2 comments](https://roxygen2.r-lib.org/articles/roxygen2.html) in an `.R`, not a `.Rd` file.
You can find the `.R` file that generates the `.Rd` by reading the comment in the first line.

## Bigger changes

If you want to make a bigger change, it's a good idea to first file an issue and make sure someone from the team agrees that it’s needed.
If you’ve found a bug, please file an issue that illustrates the bug with a minimal
[reprex](https://www.tidyverse.org/help/#reprex) (this will also help you write a unit test, if needed).

### Pull request process

* Fork the package and clone onto your computer. If you haven't done this before, we recommend using `usethis::create_from_github("massimoaria/openalexR", fork = TRUE)`.

* Install all development dependencies with `devtools::install_dev_deps()`, and then make sure the package passes R CMD check by running `devtools::check()`.
If R CMD check doesn't pass cleanly, it's a good idea to ask for help before continuing.
* Create a Git branch for your pull request (PR). We recommend using `usethis::pr_init("brief-description-of-change")`.

* Make your changes, commit to git, and then create a PR by running `usethis::pr_push()`, and following the prompts in your browser.
The title of your PR should briefly describe the change.
The body of your PR should contain `Fixes #issue-number`.

* For user-facing changes, add a bullet to the top of `NEWS.md` (i.e. just below the first header). Follow the style described in <https://style.tidyverse.org/news.html>.

### Code style

* New code should follow the tidyverse [style guide](https://style.tidyverse.org).
You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR.

* We use [roxygen2](https://cran.r-project.org/package=roxygen2), with [Markdown syntax](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd-formatting.html), for documentation.

* We use [testthat](https://cran.r-project.org/package=testthat) for unit tests.
Contributions with test cases included are easier to accept.

## Code of Conduct

Please note that the openalexR project is released with a
[Contributor Code of Conduct](https://ropensci.org/code-of-conduct/).
By contributing to this project you agree to abide by its terms.
21 changes: 21 additions & 0 deletions .github/workflows/pkgcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: pkgcheck

# This will cancel running jobs once a new run is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
# Manually trigger the Action under Actions/pkgcheck
workflow_dispatch:
# Run on every push to main
push:
branches:
- main
- for-ropensci

jobs:
pkgcheck:
runs-on: ubuntu-latest
steps:
- uses: ropensci-review-tools/pkgcheck-action@main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ docs
vignettes/*.R
vignettes/*.html
concept-abbre.csv
dev/
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: openalexR
Title: Getting Bibliographic Records from 'OpenAlex' Database Using 'DSL'
API
Version: 1.0.1
Version: 1.0.2
Authors@R: c(
person(given = "Massimo",
family = "Aria",
Expand Down
3 changes: 2 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#' Index of Countries and their alpha-2 and aplha-3 codes.
#'
#' Data frame contains the list of countries and their alpha-2 and aplha-3 codes.\cr
#' Data frame contains the list of countries and their alpha-2 and
#' aplha-3 codes.\cr
#'
#' @format A data frame with 250 rows and 3 variables:
#' \describe{
Expand Down
87 changes: 57 additions & 30 deletions R/oa2df.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' Ignored if entity is different from "works". Defaults to TRUE.
#' @inheritParams oa_query
#' @inheritParams oa_request
#' @return A tibble/dataframe result of the original OpenAlex result list.
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -38,16 +39,17 @@
#' )
#'
#' oa2df(res, entity = "works")
#'
#' }
#'
#' @export
oa2df <- function(data, entity, abstract = TRUE, count_only = FALSE, group_by = NULL, verbose = TRUE) {
if (!is.null(group_by)){
if (!is.null(group_by)) {
return(do.call(rbind.data.frame, data))
}

if (count_only && length(data) == 4) return(unlist(data))
if (count_only && length(data) == 4) {
return(unlist(data))
}

switch(entity,
works = works2df(data, abstract, verbose),
Expand Down Expand Up @@ -110,7 +112,7 @@ oa2df <- function(data, entity, abstract = TRUE, count_only = FALSE, group_by =
#' }
#'
#' # @export

#'
works2df <- function(data, abstract = TRUE, verbose = TRUE) {
if (!is.null(data$id)) {
data <- list(data)
Expand Down Expand Up @@ -216,11 +218,11 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE) {
abstract_build <- function(ab) {
w <- rep(names(ab), lengths(ab))
ind <- unlist(ab)
if (is.null(ind)){
ab <- ""
} else {
ab <- paste(w[order(ind)], collapse = " ", sep = "")
if (is.null(ind)) {
return("")
}

paste(w[order(ind)], collapse = " ", sep = "")
}


Expand Down Expand Up @@ -290,8 +292,11 @@ authors2df <- function(data, verbose = TRUE) {
item <- data[[i]]

sub_identical <- item[
c("id", "works_count", "display_name", "orcid",
"works_api_url", "cited_by_count")]
c(
"id", "works_count", "display_name", "orcid",
"works_api_url", "cited_by_count"
)
]

sub_id <- list(
ids = subs_na(item$ids, type = "col_df"),
Expand All @@ -300,11 +305,13 @@ authors2df <- function(data, verbose = TRUE) {

sub_flat <- lapply(
item[c("display_name_alternatives")],
subs_na, type = "flat"
subs_na,
type = "flat"
)
sub_rbind_dfs <- lapply(
item[c("counts_by_year", "x_concepts")],
subs_na, type = "rbind_df"
subs_na,
type = "rbind_df"
)

sub_affiliation <- item$last_known_institution
Expand All @@ -314,7 +321,8 @@ authors2df <- function(data, verbose = TRUE) {
sub_affiliation <- prepend(sub_affiliation, "affiliation")

list_df[[i]] <- tibble::as_tibble(
c(sub_identical, sub_id, sub_flat, sub_rbind_dfs, sub_affiliation))
c(sub_identical, sub_id, sub_flat, sub_rbind_dfs, sub_affiliation)
)
}

col_order <- c(
Expand Down Expand Up @@ -385,10 +393,13 @@ institutions2df <- function(data, verbose = TRUE) {

item <- data[[i]]
sub_identical <- item[
c("id", "ror", "works_api_url", "type", "works_count",
c(
"id", "ror", "works_api_url", "type", "works_count",
"display_name", "country_code", "homepage_url",
"image_url", "image_thumbnail_url", "cited_by_count",
"updated_date", "created_date")]
"updated_date", "created_date"
)
]

sub_id <- list(
ids = subs_na(item$ids, type = "col_df"),
Expand All @@ -397,21 +408,25 @@ institutions2df <- function(data, verbose = TRUE) {

sub_flat <- lapply(
item[c("display_name_alternatives", "display_name_acronyms")],
subs_na, type = "flat"
subs_na,
type = "flat"
)

sub_row <- lapply(
item[c("international", "geo", "associated_institutions")],
subs_na, type = "row_df"
subs_na,
type = "row_df"
)

sub_rbind_dfs <- lapply(
item[c("counts_by_year", "x_concepts")],
subs_na, type = "rbind_df"
subs_na,
type = "rbind_df"
)

list_df[[i]] <- tibble::as_tibble(
c(sub_flat, sub_row, sub_identical, sub_id, sub_rbind_dfs))
c(sub_flat, sub_row, sub_identical, sub_id, sub_rbind_dfs)
)
}


Expand Down Expand Up @@ -487,12 +502,16 @@ venues2df <- function(data, verbose = TRUE) {
item <- data[[i]]

sub_identical <- item[
c("id", "display_name", "publisher", "works_count", "cited_by_count",
"is_oa", "is_in_doaj", "homepage_url", "works_api_url")]
c(
"id", "display_name", "publisher", "works_count", "cited_by_count",
"is_oa", "is_in_doaj", "homepage_url", "works_api_url"
)
]

sub_flat <- lapply(
item[c("issn_l", "issn")],
subs_na, type = "flat"
subs_na,
type = "flat"
)

sub_id <- list(
Expand All @@ -502,11 +521,13 @@ venues2df <- function(data, verbose = TRUE) {

sub_rbind_dfs <- lapply(
item[c("counts_by_year", "x_concepts")],
subs_na, type = "rbind_df"
subs_na,
type = "rbind_df"
)

list_df[[i]] <- tibble::as_tibble(
c(sub_identical, sub_flat, sub_id, sub_rbind_dfs))
c(sub_identical, sub_flat, sub_id, sub_rbind_dfs)
)
}

col_order <- c(
Expand Down Expand Up @@ -578,9 +599,12 @@ concepts2df <- function(data, verbose = TRUE) {
item <- data[[i]]

sub_identical <- item[
c("id", "display_name", "wikidata", "level", "description",
"image_url", "image_thumbnail_url", "works_count", "cited_by_count",
"works_api_url")]
c(
"id", "display_name", "wikidata", "level", "description",
"image_url", "image_thumbnail_url", "works_count", "cited_by_count",
"works_api_url"
)
]

sub_id <- list(
ids = subs_na(item$ids, type = "col_df"),
Expand All @@ -589,12 +613,14 @@ concepts2df <- function(data, verbose = TRUE) {

sub_rbind_dfs <- lapply(
item[c("counts_by_year", "ancestors", "related_concepts")],
subs_na, type = "rbind_df"
subs_na,
type = "rbind_df"
)

sub_row <- lapply(
item$international[c("display_name", "description")],
subs_na, type = "row_df"
subs_na,
type = "row_df"
)
names(sub_row) <- paste(names(sub_row), "international", sep = "_")

Expand Down Expand Up @@ -682,7 +708,8 @@ snowball2df <- function(data, verbose = FALSE) {

nodes_augmented <- merge(
merge(nodes, citing, all.x = TRUE),
cited_by, all.x = TRUE
cited_by,
all.x = TRUE
)

nodes_augmented$connection <- apply(
Expand Down
Loading

0 comments on commit c0d32fe

Please sign in to comment.