Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Feb 23, 2024
0 parents commit 33bd3e8
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
^link\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^README\.Rmd$
^cran-comments\.md$
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.Rdata
.httr-oauth
.DS_Store
.quarto
15 changes: 15 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Package: link
Title: Hyperlinks
Version: 0.0.0.9000
Authors@R:
person("Romain", "François", email = "romain@tada.science", role = c("aut", "cre"))
Description: Hyperlink tools for blogs.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
cli,
downlit,
glue,
rlang
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2024
COPYRIGHT HOLDER: tada⬢science
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2024 tada⬢science

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.
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(to)
importFrom(cli,cli_abort)
importFrom(rlang,enexpr)
importFrom(rlang,is_call)
importFrom(rlang,is_string)
35 changes: 35 additions & 0 deletions R/to.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
link <- function(url, text) {
glue::glue('<a href="{url}">{text}</a>')
}

#' @importFrom rlang is_string is_call enexpr
#' @importFrom cli cli_abort
#' @export
to <- function(topic, package) {
if (missing(topic)) {
if (missing(package) || !is_string(package)) {
cli_abort("{.arg package} must be a single string")
}
link(downlit::href_package(package), package)
} else {
if (!missing(package) && is_string(package)) {
text <- glue::glue("{package}::{topic}()")
url <- downlit::href_topic(topic, package = package)
if (is.na(url)) {
cli_abort("Can't find link for {text}")
}
link(url, text)
} else {
topic <- enexpr(topic)
if (!is_call(topic, "::")) {
cli_abort("{.arg topic} must be of the form <pkg>::<topic>")
}

package <- as.character(topic[[2]])
topic <- as.character(topic[[3]])
text <- glue::glue("{package}::{topic}()")

link(downlit::href_topic(topic, package = package), text)
}
}
}
41 changes: 41 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# link

<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/link)](https://CRAN.R-project.org/package=link)
<!-- badges: end -->

The goal of link is to ...

## Installation

You can install the development version of link like so:

``` r
pak::pak("tadascience/link")
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
link::to(dplyr::mutate)
link::to(package = "dplyr")
link::to("gather", package = "tidyr")
```
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# link

<!-- badges: start -->

[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN
status](https://www.r-pkg.org/badges/version/link)](https://CRAN.R-project.org/package=link)
<!-- badges: end -->

The goal of link is to …

## Installation

You can install the development version of link like so:

``` r
pak::pak("tadascience/link")
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
link::to(dplyr::mutate)
#> <a href="https://dplyr.tidyverse.org/reference/mutate.html">dplyr::mutate()</a>
link::to(package = "dplyr")
#> <a href="https://dplyr.tidyverse.org">dplyr</a>
link::to("gather", package = "tidyr")
#> <a href="https://tidyr.tidyverse.org/reference/gather.html">tidyr::gather()</a>
```
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
22 changes: 22 additions & 0 deletions link.Rproj
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 33bd3e8

Please sign in to comment.