M DESCRIPTION => DESCRIPTION +7 -3
@@ 1,6 1,6 @@
Package: forcequotes
Type: Package
-Title: forcequotes title goes here otherwise CRAN checks fail
+Title: Return Random Star Wars Quotes
Version: 0.1.0
Date: 2019-01-12
Authors@R: c(
@@ 8,7 8,9 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-5670-2640"))
)
Maintainer: Bob Rudis <bob@rud.is>
-Description: A good description goes here otherwise CRAN checks fail.
+Description: Now you can use the R 'Force' to get random quotes from your favorite
+ space opera. This is a thin wrapper to the 'Star Wars Quote API'
+ (<http://swquotes.digitaljedi.dk/home>).
URL: https://gitlab.com/hrbrmstr/forcequotes
BugReports: https://gitlab.com/hrbrmstr/forcequotes/issues
Encoding: UTF-8
@@ 20,6 22,8 @@ Depends:
R (>= 3.2.0)
Imports:
httr,
- jsonlite
+ jsonlite,
+ cli,
+ crayon
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
M NAMESPACE => NAMESPACE +4 -0
@@ 1,4 1,8 @@
# Generated by roxygen2: do not edit by hand
+export(quote_console)
+export(random_quote)
+import(cli)
+import(crayon)
import(httr)
importFrom(jsonlite,fromJSON)
M R/forcequotes-package.R => R/forcequotes-package.R +20 -4
@@ 1,12 1,28 @@
-#' ...
-#'
+#' Return Random Star Wars Quotes
+#'
+#' \if{html}{
+#' \figure{force-quotes.png}{options: align="right" alt="Figure: force-quotes.png"}
+#' }
+#'
+#' \if{latex}{
+#' \figure{force-quotes.png}{options: width=10cm}
+#' }
+#'
+#' Now you can use the R 'Force' to get random quotes from your favorite
+#' space opera. This is a thin wrapper to the 'Star Wars Quote API'
+#' (<http://swquotesapi.digitaljedi.dk/index.html> / <http://swquotes.digitaljedi.dk/home>)
+#'
#' - URL: <https://gitlab.com/hrbrmstr/forcequotes>
#' - BugReports: <https://gitlab.com/hrbrmstr/forcequotes/issues>
-#'
+#'
+#'
+#'
#' @md
#' @name forcequotes
#' @docType package
+#' @references <http://swquotesapi.digitaljedi.dk/index.html>;
+#' <http://swquotes.digitaljedi.dk/home>
#' @author Bob Rudis (bob@@rud.is)
-#' @import httr
#' @importFrom jsonlite fromJSON
+#' @import httr cli crayon
NULL
A R/quote-console.R => R/quote-console.R +19 -0
@@ 0,0 1,19 @@
+#' Get a random Star Wars quote and display it stylishly to the console
+#'
+#' @md
+#' @param faction faction (see [random_quote()])
+#' @export
+quote_console <- function(faction = NULL) {
+
+ x <- random_quote(faction)
+
+ cw <- cli::cli_sitrep()$console_width
+
+ cli::boxx(
+ label = crayon::white(strwrap(x$starWarsQuote, width = cw)),
+ width = cw,
+ float = "center",
+ border_col = "gold1"
+ )
+
+}<
\ No newline at end of file
A R/random-quote.R => R/random-quote.R +38 -0
@@ 0,0 1,38 @@
+#' Return a Random Star Wars Quote
+#'
+#' @md
+#' @param faction if not `NULL` than a value of `0:4` to specify a faction
+#' @references <http://swquotesapi.digitaljedi.dk/index.html>;
+#' <http://swquotes.digitaljedi.dk/home>
+#' @return data frame of a single quote
+#' @export
+#' @examples
+#' random_quote()
+#' random_quote(faction = 3)
+random_quote <- function(faction = NULL) {
+
+ if (!is.null(faction)) {
+ faction <- as.integer(faction[1])
+ stopifnot(faction %in% 0L:4L)
+ }
+
+ httr::GET(
+ url = "http://swquotesapi.digitaljedi.dk/api/SWQuote/RandomStarWarsQuote",
+ query = list(
+ faction = faction
+ ),
+ httr::user_agent("forcequotes R package; <https://sr.ht/~hrbrmstr/forcequotes>")
+ ) -> res
+
+ httr::stop_for_status(res)
+
+ out <- httr::content(res, as = "text")
+
+ out <- jsonlite::fromJSON(out)
+
+ out <- as.data.frame(out, stringsAsFactors=FALSE)
+ class(out) <- c("tbl_df", "tbl", "data.frame")
+
+ out
+
+}
M README.Rmd => README.Rmd +36 -2
@@ 1,10 1,10 @@
---
output: rmarkdown::github_document
editor_options:
- chunk_output_type: inline
+ chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
-knitr$opts_chunk$set(collapse=TRUE, fig.retina=2, message=FALSE, warning=FALSE)
+knitr::opts_chunk$set(collapse=TRUE, fig.retina=2, message=FALSE, warning=FALSE)
options(width=120)
```
@@ 12,14 12,25 @@ options(width=120)
[](https://codecov.io/gh/hrbrmstr/forcequotes)
[](https://cran.r-project.org/package=forcequotes)
+
+
# forcequotes
+Return Random Star Wars Quotes
+
## Description
+Now you can use the R 'Force' to get random quotes from your favorite
+space opera. This is a thin wrapper to the 'Star Wars Quote API'
+(<http://swquotesapi.digitaljedi.dk/index.html>).
+
## What's Inside The Tin
The following functions are implemented:
+- `quote_console`: Get a random Star Wars quote and display it stylishly to the console
+- `random_quote: Return a Random Star Wars Quote
+
## Installation
```{r install-ex, eval=FALSE}
@@ 38,6 49,29 @@ packageVersion("forcequotes")
```
+### Basic use
+
+```{r basics}
+random_quote()
+
+random_quote(faction=0)
+
+random_quote(faction=1)
+
+random_quote(faction=2)
+
+random_quote(faction=3)
+
+random_quote(faction=4)
+
+```
+
+### Console shenanigans
+
+```{r console}
+quote_console()
+```
+
## forcequotes Metrics
```{r cloc, echo=FALSE}
M README.md => README.md +94 -0
@@ 1,2 1,96 @@
+
+[](https://travis-ci.org/hrbrmstr/forcequotes)
+[](https://codecov.io/gh/hrbrmstr/forcequotes)
+[](https://cran.r-project.org/package=forcequotes)
+
+
+
# forcequotes
+Return Random Star Wars Quotes
+
+## Description
+
+Now you can use the R ‘Force’ to get random quotes from your favorite
+space opera. This is a thin wrapper to the ‘Star Wars Quote API’
+(<http://swquotesapi.digitaljedi.dk/index.html>).
+
+## What’s Inside The Tin
+
+The following functions are implemented:
+
+ - `quote_console`: Get a random Star Wars quote and display it
+ stylishly to the console
+ - \`random\_quote: Return a Random Star Wars Quote
+
+## Installation
+
+``` r
+devtools::install_git("https://gitlab.com/hrbrmstr/forcequotes.git")
+# or
+devtools::install_github("hrbrmstr/forcequotes")
+```
+
+## Usage
+
+``` r
+library(forcequotes)
+
+# current version
+packageVersion("forcequotes")
+## [1] '0.1.0'
+```
+
+### Basic use
+
+``` r
+random_quote()
+## id starWarsQuote faction
+## 1 42 Your focus determines your reality. ? Qui-Gon Jinn 0
+
+random_quote(faction=0)
+## id starWarsQuote faction
+## 1 25 You were my brother, Anakin. I loved you. — Obi-Wan Kenobi 0
+
+random_quote(faction=1)
+## id starWarsQuote faction
+## 1 13 This technological terror is nothing compared to the power of the force - Darth Vader 1
+
+random_quote(faction=2)
+## id starWarsQuote faction
+## 1 24 Well, if droids could think, there’d be none of us here, would there? — Obi-Wan Kenobi 0
+
+random_quote(faction=3)
+## id starWarsQuote faction
+## 1 21 Why, you stuck-up, half-witted, scruffy-looking nerf herder! — Leia Organa 0
+
+random_quote(faction=4)
+## id starWarsQuote faction
+## 1 52 Jyn, I’ll be there for you. Cassian said I had to. — K-2SO 0
+```
+
+### Console shenanigans
+
+``` r
+quote_console()
+## ┌────────────────────────────────────────────────────────────────────────┐
+## │ │
+## │ The ability to speak does not make you intelligent. ? Qui-Gon Jinn │
+## │ │
+## └────────────────────────────────────────────────────────────────────────┘
+```
+
+## forcequotes Metrics
+
+| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
+| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
+| R | 5 | 0.83 | 35 | 0.71 | 14 | 0.33 | 44 | 0.52 |
+| Rmd | 1 | 0.17 | 14 | 0.29 | 29 | 0.67 | 41 | 0.48 |
+
+## Code of Conduct
+
+Please note that this project is released with a [Contributor Code of
+Conduct](CONDUCT.md). By participating in this project you agree to
+abide by its terms.
A man/figures/force-quotes.png => man/figures/force-quotes.png +0 -0
M man/forcequotes.Rd => man/forcequotes.Rd +17 -1
@@ 4,13 4,29 @@
\name{forcequotes}
\alias{forcequotes}
\alias{forcequotes-package}
-\title{...}
+\title{Return Random Star Wars Quotes}
\description{
+\if{html}{
+\figure{force-quotes.png}{options: align="right" alt="Figure: force-quotes.png"}
+}
+}
+\details{
+\if{latex}{
+\figure{force-quotes.png}{options: width=10cm}
+}
+
+Now you can use the R 'Force' to get random quotes from your favorite
+space opera. This is a thin wrapper to the 'Star Wars Quote API'
+(\url{http://swquotesapi.digitaljedi.dk/index.html} / \url{http://swquotes.digitaljedi.dk/home})
\itemize{
\item URL: \url{https://gitlab.com/hrbrmstr/forcequotes}
\item BugReports: \url{https://gitlab.com/hrbrmstr/forcequotes/issues}
}
}
+\references{
+\url{http://swquotesapi.digitaljedi.dk/index.html};
+\url{http://swquotes.digitaljedi.dk/home}
+}
\author{
Bob Rudis (bob@rud.is)
}
A man/quote_console.Rd => man/quote_console.Rd +14 -0
@@ 0,0 1,14 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/quote-console.R
+\name{quote_console}
+\alias{quote_console}
+\title{Get a random Star Wars quote and display it stylishly to the console}
+\usage{
+quote_console(faction = NULL)
+}
+\arguments{
+\item{faction}{faction (see \code{\link[=random_quote]{random_quote()}})}
+}
+\description{
+Get a random Star Wars quote and display it stylishly to the console
+}
A man/random_quote.Rd => man/random_quote.Rd +25 -0
@@ 0,0 1,25 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/random-quote.R
+\name{random_quote}
+\alias{random_quote}
+\title{Return a Random Star Wars Quote}
+\usage{
+random_quote(faction = NULL)
+}
+\arguments{
+\item{faction}{if not \code{NULL} than a value of \code{0:4} to specify a faction}
+}
+\value{
+data frame of a single quote
+}
+\description{
+Return a Random Star Wars Quote
+}
+\examples{
+random_quote()
+random_quote(faction = 3)
+}
+\references{
+\url{http://swquotesapi.digitaljedi.dk/index.html};
+\url{http://swquotes.digitaljedi.dk/home}
+}