Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review search_references() #85

Merged
merged 2 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.RData
.Rhistory
doc
docs
Meta
2 changes: 1 addition & 1 deletion R/get_collection.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ get_collection.mgSearchNetworks <- function(x, ...) {
#' @export
get_collection.mgSearchReferences <- function(x, ...) {
# Get networks ids
net_ids <- unique(x$networks$id)
net_ids <- unique(unlist(purrr::map(x$networks, "id")))
get_network_by_id(net_ids, ...)
}

Expand Down
4 changes: 2 additions & 2 deletions R/search_networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ search_networks <- function(query, verbose = TRUE, ...) {
search_networks_sf <- function(query_sf, verbose = TRUE, ...) {
stopifnot("sf" %in% class(query_sf))

if(!("sf" %in% row.names(utils::installed.packages())))
message("The package sf is not installed.")
if (!("sf" %in% row.names(utils::installed.packages())))
stop("Package sf is not installed.")

# API doesn't allow spatial search yet, so we sort with sf package
sp_networks_all <- resp_to_spatial(
Expand Down
23 changes: 14 additions & 9 deletions R/search_references.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' An object of class `mgSearchReferences`, which is a list that includes a wide range of details associated to the reference, including all datasets and networks related to the publication that are included in Mangal database.
#'
#' @details
#' Names of the list should match one of the column names within the table.
#' Names of the list should match one of the column names within the table.
#' For the `reference` table, those are:
#' - id: unique identifier of the reference
#' - first_author: first author
Expand All @@ -32,6 +32,7 @@
#' @examples
#' search_references(doi = "10.2307/3225248")
#' search_references(list(jstor = 3683041))
#' search_references(list(year = 2010))
#' @export

search_references <- function(query, doi = NULL, verbose = TRUE, ...) {
Expand All @@ -44,7 +45,6 @@ search_references <- function(query, doi = NULL, verbose = TRUE, ...) {
query <- list(doi = as.character(doi))
} else query <- handle_query(query, c("id" ,"author", "doi", "jstor", "year"))


ref <- resp_to_df(get_gen(endpoints()$reference, query = query,
verbose = verbose, ...)$body)

Expand All @@ -54,15 +54,20 @@ search_references <- function(query, doi = NULL, verbose = TRUE, ...) {
}

if (verbose)
message(sprintf("Found %s reference", nrow(ref)))
message(sprintf("Found %s reference(s)", nrow(ref)))

# Attach dataset
ref$datasets <- get_from_fkey(endpoints()$dataset, ref_id = ref$id,
verbose = verbose)
# Attach dataset(s)
ref$datasets <- do.call(
rbind,
lapply(ref$id, function(x)
get_from_fkey(endpoints()$dataset, ref_id = x, verbose = verbose))
)

# Attach network
ref$networks <- get_from_fkey_net(endpoints()$network,
dataset_id = ref$datasets$id, verbose = verbose)
# Attach network(s)
ref$networks <- lapply(ref$datasets$id, function(x)
get_from_fkey_net(endpoints()$network, dataset_id = x,
verbose = verbose))
# ref$networks <- do.call(rbind, lapply(tmp, function(x) x$id))

class(ref) <- "mgSearchReferences"
ref
Expand Down
127 changes: 0 additions & 127 deletions docs/404.html

This file was deleted.

138 changes: 0 additions & 138 deletions docs/CODE_OF_CONDUCT.html

This file was deleted.

Loading