Create an HTML Link to Repository Resources or GitHub Pages
Source:R/ngr_str_link_url.R
ngr_str_link_url.Rd
This function generates an HTML <a>
tag linking to a url or a url related to specified repository resource or
GitHub Pages site hosted from the repository. It is particularly useful for embedding links in html tables such as DT tables.
Usage
ngr_str_link_url(
url_base = "https://www.newgraphenvironment.com",
url_resource = NULL,
url_resource_path = TRUE,
anchor_text = "url_link",
target = "_blank"
)
Arguments
- url_base
character A character vector specifying either the URL(s) to link to or (if
url_resource
is provided) the base URL(s) for the repository host. Default is New Graph gitpages at _base{https://www.newgraphenvironment.com"
. _base{https://github.com/NewGraphEnvironment
Value
character A character vector containing the HTML <a>
tags.
See also
Other string:
ngr_str_dir_from_path()
Examples
# Example 1: Link to the repository with default anchor text
ngr_str_link_url("ngr", url_base = "https://github.com/NewGraphEnvironment")
#> [1] "<a href=\"https://github.com/NewGraphEnvironment/ngr\" target=\"_blank\">url_link</a>"
# Example 2: Link to GitHub Pages with anchor text set to the repository name
ngr_str_link_url(url_resource = "ngr", anchor_text = "ngr")
#> [1] "<a href=\"https://www.newgraphenvironment.com/ngr\" target=\"_blank\">ngr</a>"
# Example 3: Link with no url_resource
ngr_str_link_url(url_base = "https://www.newgraphenvironment.com", anchor_text = "Visit New Graph")
#> [1] "<a href=\"https://www.newgraphenvironment.com\" target=\"_blank\">Visit New Graph</a>"
# Example 4: Use in a dplyr::mutate()
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
df <- data.frame(
url_resource = c("ngr", "fpr"),
url_base = c("https://github.com/NewGraphEnvironment", "https://www.newgraphenvironment.com")
)
df <- df %>%
mutate(
link = ngr_str_link_url(url_resource = url_resource, url_base = url_base, anchor_text = url_resource)
)
print(df$link)
#> [1] "<a href=\"https://github.com/NewGraphEnvironment/ngr\" target=\"_blank\">ngr</a>"
#> [2] "<a href=\"https://www.newgraphenvironment.com/fpr\" target=\"_blank\">fpr</a>"