Commit c7d3f3f0 authored by Karthik Ram's avatar Karthik Ram
Browse files

temp stuff

parent 394e8b41
language: c
script: "./travis-tool.sh run_tests"
before_script:
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
- chmod 755 ./travis-tool.sh
- "./travis-tool.sh bootstrap"
- "./travis-tool.sh install_deps"
language: r
notifications:
slack:
secure: PcdJMRncDb0dO4bGZLc8tcjhakOdhglyNQr8acdL1Wrq23Qb+ZF6fFfaahrbpSRD+pdpnXUXkmhWjbuqfHY1mnvC9gsFMr9KD9P82hJs2luRUs+mZBKWU45v4puAm19Zepr0P/rsj0KUJmcJepsxLo1ccjOY0xSxzf7jvyf8lx0=
Package: rAltmetric2
Package: rAltmetric
Title: Provides a programmatic interface the the Altmetric.com API on article level metrics.
Version: 0.1.0.9000
Version: 1.0.0.99
Authors@R: 'Karthik Ram <karthik.ram@gmail.com> [aut, cre]'
Description: The package allows for retrieval of metrics on various
Description: Programmatic interface to the Altmetric.com API.
Depends: R (>= 3.1.1)
License: MIT + file LICENSE
LazyData: true
Imports:
Imports:
assertthat,
httr,
jsonlite
Suggests:
dplyr
......@@ -2,5 +2,5 @@
export(citations)
export(metrics)
import(assertthat)
import(httr)
importFrom(assertthat,assert_that)
#' Retrieves most popular articles over a defined time period
#'
#'
#' The time period can be any of the following: '1d', '2d', '3d', '4d', '5d', '6d', '1w', '1m', '3m', '6m', '1y'
#' @param day The time period over which metrics are required. Allowed options include '1d', '2d', '3d', '4d', '5d', '6d', '1w', '1m', '3m', '6m', '1y'resu
#' @param page Page number
......@@ -10,9 +10,8 @@
#' @param subject Comma delimited list of slugified journal subjects. Include only articles from journals matching any of the supplied NLM subject ontology term(s).
#' @param foptions A list of additional arguments for \code{httr}. There is no reason to use this argument except for debugging purposes.
#' @import httr
#' @importFrom assertthat assert_that
#' @export
#' @examples
#' @examples
#' citations(day = '1d')
#' # Only Facebook mentions
#' fb_1week <- citations('1w', cited_in = "facebook")
......@@ -28,7 +27,18 @@ citations <- function(day, page = NULL, num_results = 100, cited_in = NULL, doi_
warn_for_status(data)
results <- content(data, as = 'text')
res <- jsonlite::fromJSON(results, flatten = TRUE)
res$results <- as.data.frame(apply(res$results, 2, flat_list))
res$query <- data.frame(t(unlist(res$query)))
class(res) <- "altmetric"
res
}
\ No newline at end of file
}
#' NoRd
#' @param foo input column
flat_list <- function(foo) {
if(identical(class(foo), "list")) {
foo <- vapply(foo, paste, collapse = ", ", character(1L))
}
foo
}
#' Metrics
#'
#' Returns metrics for any standard identifier such as doi, arxiv, pmid, id, or ads.
#' @param identifier The identifier passed in the format "identifier/id".
#' @param identifier The identifier passed in the format "identifier/id".
#' @export
#' @import assertthat
#' @examples \dontrun{
#' foo <- metrics(identifier = "arxiv/1108.2455")
#' foo <- metrics(identifier = "arxiv/1108.2455")
#' # This is a failed example
#' foo <- metrics(identifier = "arxiv/1108.24553")
#' foo <- metrics(identifier = "arxiv/1108.24553")
#' # Now for a PMID
#' pm <- metrics(identifier = "pmid/21148220")
#' pm <- metrics(identifier = "pmid/21148220")
#'}
metrics <- function(identifier) {
assert_that(!is.null(identifier))
......@@ -17,7 +18,7 @@ metrics <- function(identifier) {
assert_that(type %in% possible_types)
metrics_url <- paste0(api_url(), dirname(identifier), "/", basename(identifier))
# message(sprintf("Calling %s \n", metrics_url))
data <- GET(metrics_url)
data <- GET(metrics_url)
if(data$status_code == 404) {
message("No metrics found")
NULL
......@@ -26,11 +27,18 @@ metrics <- function(identifier) {
results <- content(data, as = 'text')
# Needs more clean up here
res <- jsonlite::fromJSON(results, flatten = TRUE)
res
res <- sapply(res, flatten_nested_list)
do.call(cbind, res)
}
}
#' @param panda input foo
#' @noRd
flatten_nested_list <- function(panda) {
fnames <- names(panda)
z <- data.frame(t(unlist(panda)))
names(z) <- fnames
z
}
# Altmetric2
# Altmetric
This is the reworked version of rAltmetric (temp repo will get merged into rAltmetric shortly)
\ No newline at end of file
This package provides a way to programmatically retrieve altmetric data from [altmetric.com](http://altmetric.com) for any publication with the appropriate identifer.
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/citations.R
\name{flat_list}
\alias{flat_list}
\title{NoRd}
\usage{
flat_list(foo)
}
\arguments{
\item{foo}{input column}
}
\description{
NoRd
}
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment