Skip to content
Snippets Groups Projects
Commit 018143e0 authored by LAFORÊT Nicolas's avatar LAFORÊT Nicolas :rabbit2:
Browse files

:tada: Initial commit

- :sparkles: Basic OpenCPU R application
parents
No related merge requests found
^.*\.Rproj$
^\.Rproj\.user$
.Rproj.user
.Rhistory
.RData
.project 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>opencpu_r_api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
Package: opencpu_r_api
Type: Package
Title: R API application with OpenCPU
Version: 0.1.0
Date: 2022-05-17
Description: OpenCPU application to provide a REST API for R.
License: GPL
Imports:
ggplot2,
curl,
jsonlite,
reshape2
RoxygenNote: 6.0.1
# Generated by roxygen2: do not edit by hand
export(opencpu_r_api)
import(curl)
import(ggplot2)
import(jsonlite)
import(reshape2)
#' OpenCPU application to provide a REST API for R
#'
#' Plots the total number of forks and stars for all repositories of
#' a user or organization.
#'
#' @param id name of the github user or organization. Default: "Hadley"
#' @param type either "users" (default) or "orgs"
#' @param max maximum number of repositories to plot. Default: 20, max: 100
#' @import ggplot2 curl jsonlite reshape2
#' @export
#' @examples \dontrun{
#' opencpu_r_api(max = 10)
#' opencpu_r_api(max = 40)
#' opencpu_r_api(id = "jeroen", max = 30)
#' opencpu_r_api(id = "ropensci", type = "orgs", max = 70)
#' }
opencpu_r_api <- function (id = "hadley", type = c("users", "orgs"), max = 20) {
type <- match.arg(type, choices=c('users','orgs'))
max <- min(max, 100)
#call github API using jsonlite
url <- file.path("https://api.github.com", type, id, "repos")
url <- paste0(url, "?type=owner&sort=pushed&per_page=100")
out <- jsonlite::fromJSON(url, flatten = TRUE)
#resort factor)
out <- out[order(out$watchers, decreasing = TRUE)[seq_len(max)],
c("name", "watchers", "forks", "open_issues")]
out$name <- factor(out$name, levels = rev(out$name))
#reshape to "long" dataframe"
names(out) <- c("Repo", "Stars", "Forks", "Issues")
out2 <- reshape2::melt(out, id = 1)
#create ggplot object
time <- format(Sys.time(), tz = 'UTC', usetz = TRUE)
ggplot(out2, aes(Repo, value)) + geom_bar(stat="identity") + coord_flip() +
facet_wrap(~variable, scales = "free_x") + xlab("") + ylab("") +
ggtitle(sprintf("Github stats from: '%s' (%s)", id, time))
}
\ No newline at end of file
# OpenCPU R REST API
A simple OpenCPU application to provide a REST API for R. To install in R:
```R
library(opencpu)
ocpu_start_app("rwebapps/opencpu_r_api")
```
Use the same function locally:
```R
library(rwebapps)
opencpu_r_api()
```
For more information about OpenCPU apps, see [opencpu.js](https://www.opencpu.org/apps.html)
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/opencpu_r_api.R
\name{opencpu_r_api}
\alias{opencpu_r_api}
\title{OpenCPU application to provide a REST API for R}
\usage{
opencpu_r_api(id = "hadley", type = c("users", "orgs"), max = 20)
}
\arguments{
\item{id}{name of the github user or organization. Default: "Hadley"}
\item{type}{either "users" (default) or "orgs"}
\item{max}{maximum number of repositories to plot. Default: 20, max: 100}
}
\description{
Plots the total number of forks and stars for all repositories of
a user or organization.
}
\examples{
\dontrun{
opencpu_r_api(max = 10)
opencpu_r_api(max = 40)
opencpu_r_api(id = "jeroen", max = 30)
opencpu_r_api(id = "ropensci", type = "orgs", max = 70)
}
}
Version: 0.1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
BuildType: Package
PackageInstallArgs: --no-multiarch --with-keep.source
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