From 740e088a3a4720d876d8205a32d1b87a9bfdb2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 8 Oct 2024 10:19:07 +0200 Subject: [PATCH] Initial commit --- .Rbuildignore | 3 +++ .gitignore | 6 ++++++ DESCRIPTION | 16 ++++++++++++++++ LICENSE | 2 ++ LICENSE.md | 21 +++++++++++++++++++++ NAMESPACE | 3 +++ R/starchart-package.R | 6 ++++++ R/universe.R | 22 ++++++++++++++++++++++ R/utils.R | 8 ++++++++ man/starchart-package.Rd | 15 +++++++++++++++ man/universe_ls.Rd | 23 +++++++++++++++++++++++ starchart.Rproj | 22 ++++++++++++++++++++++ 12 files changed, 147 insertions(+) create mode 100644 .Rbuildignore create mode 100644 .gitignore create mode 100644 DESCRIPTION create mode 100644 LICENSE create mode 100644 LICENSE.md create mode 100644 NAMESPACE create mode 100644 R/starchart-package.R create mode 100644 R/universe.R create mode 100644 R/utils.R create mode 100644 man/starchart-package.Rd create mode 100644 man/universe_ls.Rd create mode 100644 starchart.Rproj diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..62e7f5b --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,3 @@ +^starchart\.Rproj$ +^\.Rproj\.user$ +^LICENSE\.md$ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c794aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.Rproj.user +.Rhistory +.Rdata +.httr-oauth +.DS_Store +.quarto diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..d3d5c6e --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,16 @@ +Package: starchart +Title: 'R-Universe' 'API' +Version: 0.0.0.9000 +Authors@R: + person("Maëlle", "Salmon", , "msmaellesalmon@gmail.com", role = c("cre", "aut"), + comment = c(ORCID = "0000-0002-2815-0399")) +Description: Client to access the 'R-Universe' 'API'. +License: MIT + file LICENSE +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.2 +Depends: + R (>= 4.2.0) +Imports: + cli, + httr2 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e3a5986 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2024 +COPYRIGHT HOLDER: starchart authors diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ce7ab49 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2024 starchart authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..65a3aa7 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(universe_ls) diff --git a/R/starchart-package.R b/R/starchart-package.R new file mode 100644 index 0000000..a65cf64 --- /dev/null +++ b/R/starchart-package.R @@ -0,0 +1,6 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +## usethis namespace: end +NULL diff --git a/R/universe.R b/R/universe.R new file mode 100644 index 0000000..96da412 --- /dev/null +++ b/R/universe.R @@ -0,0 +1,22 @@ +#' All packages in an universe +#' +#' @param universe Name of the universe (character of length 1) +#' +#' @return A character vector of all packages in the universe. +#' @export +#' +#' @examplesIf interactive() +#' universe_ls("jeroen") +#' universe_ls("ropensci") +universe_ls <- function(universe) { + if (!is.character(universe) || length(universe) != 1) { + cli::cli_abort("{.arg universe} must be a character of length 1.") + } + # TODO assert that universe is an universe + + universe_query( + universe_url = sprintf("https://%s.r-universe.dev", universe), + path = "ls" + ) |> + unlist() +} diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..09a4839 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,8 @@ +universe_query <- function(universe_url, path) { + httr2::request(universe_url) |> + httr2::req_url_path("api") |> + httr2::req_url_path_append(path) |> + httr2::req_user_agent("starchart R package") |> + httr2::req_perform() |> + httr2::resp_body_json() +} diff --git a/man/starchart-package.Rd b/man/starchart-package.Rd new file mode 100644 index 0000000..e69c690 --- /dev/null +++ b/man/starchart-package.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/starchart-package.R +\docType{package} +\name{starchart-package} +\alias{starchart} +\alias{starchart-package} +\title{starchart: 'R-Universe' 'API'} +\description{ +Client to access the 'R-Universe' 'API'. +} +\author{ +\strong{Maintainer}: Maëlle Salmon \email{msmaellesalmon@gmail.com} (\href{https://orcid.org/0000-0002-2815-0399}{ORCID}) + +} +\keyword{internal} diff --git a/man/universe_ls.Rd b/man/universe_ls.Rd new file mode 100644 index 0000000..491c3a1 --- /dev/null +++ b/man/universe_ls.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/universe.R +\name{universe_ls} +\alias{universe_ls} +\title{All packages in an universe} +\usage{ +universe_ls(universe) +} +\arguments{ +\item{universe}{Name of the universe (character of length 1)} +} +\value{ +A character vector of all packages in the universe. +} +\description{ +All packages in an universe +} +\examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +universe_ls("jeroen") +universe_ls("ropensci") +\dontshow{\}) # examplesIf} +} diff --git a/starchart.Rproj b/starchart.Rproj new file mode 100644 index 0000000..69fafd4 --- /dev/null +++ b/starchart.Rproj @@ -0,0 +1,22 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace