Skip to content

Commit

Permalink
fix imgur
Browse files Browse the repository at this point in the history
fix vignettes for cran
  • Loading branch information
yonicd committed Feb 1, 2025
1 parent c8dc184 commit 04f4867
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 117 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
^CRAN-RELEASE$
^data-raw$
^CRAN-SUBMISSION$
^\.httr-oauth$
11 changes: 5 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: details
Title: Create Details HTML Tag for Markdown and Package
Documentation
Version: 0.3.0
Version: 0.4.0
Authors@R:
person(given = "Jonathan",
family = "Sidi",
Expand All @@ -13,20 +13,19 @@ License: MIT + file LICENSE
URL: https://github.com/yonicd/details
BugReports: https://github.com/yonicd/details/issues
Depends:
R (>= 3.2.0)
R (>= 4.2.0)
Imports:
clipr,
desc,
grid,
httr,
xfun,
htmltools,
knitr,
magrittr,
png,
stats,
utils,
withr,
xml2
httr
Suggests:
covr,
rmarkdown,
Expand All @@ -38,4 +37,4 @@ VignetteBuilder:
Encoding: UTF-8
LazyData: false
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.3.2
12 changes: 2 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ S3method(print,details_character)
S3method(print,details_clipr)
S3method(print,details_console)
S3method(print,details_edit)
export("%>%")
export(details)
export(foldend)
export(foldstart)
Expand All @@ -24,23 +23,16 @@ importFrom(grid,grid.raster)
importFrom(grid,unit)
importFrom(htmltools,HTML)
importFrom(httr,HEAD)
importFrom(httr,POST)
importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(httr,stop_for_status)
importFrom(httr,timeout)
importFrom(httr,upload_file)
importFrom(knitr,engine_output)
importFrom(knitr,fig_path)
importFrom(knitr,knit_print)
importFrom(knitr,sew)
importFrom(magrittr,"%>%")
importFrom(png,readPNG)
importFrom(stats,setNames)
importFrom(utils,capture.output)
importFrom(utils,file.edit)
importFrom(utils,getFromNamespace)
importFrom(utils,packageVersion)
importFrom(withr,with_png)
importFrom(xml2,as_list)
importFrom(xml2,read_xml)
importFrom(xfun,is_windows)
importFrom(xfun,upload_imgur)
2 changes: 1 addition & 1 deletion R/details.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' \donttest{
#' details(
#' plot(x = mtcars$mpg, y = mtcars$wt),
#' summary = 'Plots')
#' summary = 'Plots', imgur = interactive())
#' }
#'
#' #output options
Expand Down
52 changes: 26 additions & 26 deletions R/device.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,46 @@ device_check <- function(object,f_png = tempfile(fileext = ".png"), env){
}

# augmented function from https://github.com/yihui/knitr/blob/a6cc50b09314ee0243b5d3223090fe4ecc9a13cd/R/utils-upload.R
#' @importFrom httr POST add_headers upload_file stop_for_status content
#' @importFrom xml2 as_list read_xml
#' @importFrom utils packageVersion
imgur_upload <- function (file, key = "9f3460e67f308f6",only_link = TRUE){
# @importFrom httr POST add_headers upload_file stop_for_status content
# @importFrom xml2 as_list read_xml
# @importFrom utils packageVersion
# imgur_upload <- function (file, key = "9f3460e67f308f6",only_link = TRUE){

check_internet('imgur.com')
# check_internet('imgur.com')

if (!is.character(key))
stop("The Imgur API Key must be a character string!")
# if (!is.character(key))
# stop("The Imgur API Key must be a character string!")

resp <- httr::POST(
"https://api.imgur.com/3/image.xml",
config = httr::add_headers(Authorization = paste("Client-ID", key)),
body = list(image = httr::upload_file(file))
)
# resp <- httr::POST(
# "https://api.imgur.com/3/image.xml",
# config = httr::add_headers(Authorization = paste("Client-ID", key)),
# body = list(image = httr::upload_file(file))
# )

httr::stop_for_status(resp, "upload to imgur")
# httr::stop_for_status(resp, "upload to imgur")

res <- httr::content(resp, as = "raw")
# res <- httr::content(resp, as = "raw")

res <- if (length(res))
xml2::as_list(xml2::read_xml(res))
# res <- if (length(res))
# xml2::as_list(xml2::read_xml(res))

if (utils::packageVersion("xml2") >= "1.2.0")
res <- res[[1L]]
# if (utils::packageVersion("xml2") >= "1.2.0")
# res <- res[[1L]]

if (is.null(res$link[[1]]))
stop("failed to upload ", file)
# if (is.null(res$link[[1]]))
# stop("failed to upload ", file)

if(only_link){
# if(only_link){

res$link[[1]]
# res$link[[1]]

}else{
# }else{

structure(res$link[[1]], XML = res)
# structure(res$link[[1]], XML = res)

}
# }

}
# }

is_not_na_png <- function(file){
!is.na(file.size(file))
Expand Down
14 changes: 10 additions & 4 deletions R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' @importFrom knitr fig_path engine_output sew
#' @importFrom grid grid.raster convertUnit unit
#' @importFrom png readPNG
#' @importFrom xfun is_windows
eng_detail <- function (options) {

type <- options$type %n% "details"
Expand Down Expand Up @@ -46,12 +47,12 @@ eng_detail <- function (options) {

if(length(attr(code,'file'))>0){

this <- attr(code,'file')
this <- normalizePath(attr(code,'file'), mustWork = FALSE)

plot_counter <- utils::getFromNamespace("plot_counter", "knitr")
in_base_dir <- utils::getFromNamespace("in_base_dir", "knitr")

tmp <- knitr::fig_path('png', number = plot_counter())
tmp <- normalizePath(knitr::fig_path('png', number = plot_counter()), mustWork = FALSE)
tmp <- structure(tmp,class = c('knit_image_paths',class(tmp)))

if(!grepl('^-',tmp)){
Expand All @@ -60,8 +61,13 @@ eng_detail <- function (options) {
dir.create(dirname(tmp), showWarnings = FALSE, recursive = TRUE)
file.copy(this,tmp)
})

code <- gsub(this,knitr::sew(tmp),code)

if(xfun::is_windows()){
message('details knitr plots in winos disabled')
code <- knitr::sew(tmp)
}else{
code <- gsub(this,knitr::sew(tmp),code)
}

}else{

Expand Down
13 changes: 10 additions & 3 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,26 @@ if (!length(attr(x,'file')))
return(invisible())

this <- attr(x,'file')

this <- normalizePath(this, mustWork = FALSE)

plot_counter <- utils::getFromNamespace("plot_counter", "knitr")
in_base_dir <- utils::getFromNamespace("in_base_dir", "knitr")

tmp <- knitr::fig_path('png', number = plot_counter())
tmp <- normalizePath(knitr::fig_path('png', number = plot_counter()), mustWork = FALSE)
tmp <- structure(tmp,class = c('knit_image_paths',class(tmp)))

in_base_dir({
dir.create(dirname(tmp), showWarnings = FALSE, recursive = TRUE)
file.copy(this,tmp)
})

if(xfun::is_windows()){
message('details knitr plots in winos disabled')
x <- knitr::sew(tmp)
}else{
x <- gsub(this,knitr::sew(tmp),x)
}

x <- gsub(this,knitr::sew(tmp),x)

knitr::asis_output(x)

Expand Down
17 changes: 10 additions & 7 deletions R/read.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#' @importFrom utils capture.output
capture.print <- function(obj,comment = NA,...){
#' @importFrom xfun upload_imgur
capture.print <- function(obj, comment = NA,...){

if(details_env$device){

if(details_env$imgur)
obj <- sprintf('![](%s)',imgur_upload(obj))
if(details_env$imgur){
imgur_res <- xfun::upload_imgur(obj, include_xml = TRUE)
obj <- sprintf('![](%s)', imgur_res$link)
}

}else{

if(!inherits(obj,'character')){
if(!inherits(obj, 'character')){

obj <- utils::capture.output(print(obj,...))
obj <- utils::capture.output(print(obj, ...))

}

}

if(!is.na(comment))
obj <- paste0(comment,' ',obj)
obj <- paste0(comment, ' ', obj)

paste0(obj,collapse = '\n')
paste0(obj, collapse = '\n')
}

read_text <- function(text){
Expand Down
8 changes: 0 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#' @title re-export magrittr pipe operators
#'
#' @importFrom magrittr %>%
#' @name %>%
#' @rdname pipe
#' @export
NULL

details_env <- new.env()
details_env$device <- FALSE
details_env$imgur <- TRUE
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ knitr::opts_chunk$set(
[![R-mac build status](https://github.com/yonicd/details/workflows/R-mac/badge.svg)](https://github.com/yonicd/details)
[![R-linux build status](https://github.com/yonicd/details/workflows/R-linux/badge.svg)](https://github.com/yonicd/details)
[![Codecov test coverage](https://codecov.io/gh/yonicd/details/branch/master/graph/badge.svg)](https://app.codecov.io/gh/yonicd/details?branch=master)
[![Covrpage Summary](https://img.shields.io/badge/covrpage-Last_Build_2021_01_13-yellowgreen.svg)](http://tinyurl.com/yyodcwc7)
[![Covrpage Summary](https://img.shields.io/badge/covrpage-Last_Build_2021_01_13-yellowgreen.svg)](https://github.com/yonicd/details/blob/master/tests/README.md)
<!-- badges: end -->


Expand Down Expand Up @@ -87,7 +87,7 @@ One the most popular uses for `details` is to paste the sessioninfo at the botto
```{r}
library(details)
sessioninfo::session_info()%>%
sessioninfo::session_info()|>
details::details(summary = 'current session info')
```

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ status](https://github.com/yonicd/details/workflows/R-linux/badge.svg)](https://
[![Codecov test
coverage](https://codecov.io/gh/yonicd/details/branch/master/graph/badge.svg)](https://app.codecov.io/gh/yonicd/details?branch=master)
[![Covrpage
Summary](https://img.shields.io/badge/covrpage-Last_Build_2021_01_13-yellowgreen.svg)](http://tinyurl.com/yyodcwc7)
Summary](https://img.shields.io/badge/covrpage-Last_Build_2021_01_13-yellowgreen.svg)](https://github.com/yonicd/details/blob/master/tests/README.md)
<!-- badges: end -->

# details <img src="man/figures/logo.png" align="right" class="logo" style="height:150px;"/>
Expand Down Expand Up @@ -87,7 +87,7 @@ the bottom of a GitHub issue.
``` r
library(details)

sessioninfo::session_info()%>%
sessioninfo::session_info()|>
details::details(summary = 'current session info')
```

Expand Down
36 changes: 18 additions & 18 deletions input/bunny.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,45 @@ hex_canvas <- image_canvas_hex(border_color="#000000", border_size = 2,
fill_color = "#FFFFFF")
hex_border <- image_canvas_hexborder(border_color="#000000", border_size = 3)

img_hex <- hex_canvas %>%
img_hex <- hex_canvas |>
magick::image_annotate("<", size=450, gravity = "center",
font = "Fira Code", color = "#000000",
location = '-675-50')%>%
location = '-675-50')|>
magick::image_annotate(">", size=450, gravity = "center",
font = "Fira Code", color = "#000000",
location = '+675-50')%>%
location = '+675-50')|>
magick::image_annotate("details", size=450, gravity = "center",
font = "Black Jack", color = "#0d4448")%>%
font = "Black Jack", color = "#0d4448")|>
bunny::image_compose(hex_border, gravity = "center", operator = "Over")


img_hex %>%
magick::image_scale("200x200")%>%
img_hex |>
magick::image_scale("200x200")|>
magick::image_write(here::here("input", "logo.png"), density = 600)

img_hex %>%
magick::image_scale("100x100")%>%
img_hex |>
magick::image_scale("100x100")|>
magick::image_write(here::here("input", "pkgdown.png"), density = 600)

img_hex%>%
magick::image_scale("1200x1200") %>%
img_hex|>
magick::image_scale("1200x1200") |>
magick::image_write(here::here("input", "hex.png"), density = 600)


img_hex_gh <- img_hex %>%
img_hex_gh <- img_hex |>
image_scale("400x400")

gh_logo <- bunny::github %>%
gh_logo <- bunny::github |>
image_scale("50x50")

gh <- image_canvas_ghcard() %>%
image_compose(img_hex_gh, gravity = "East", offset = "+40+0") %>%
gh <- image_canvas_ghcard() |>
image_compose(img_hex_gh, gravity = "East", offset = "+40+0") |>
image_annotate("Saying More With Less", gravity = "West", location = "+50-30",
color="#0d4448", size=60, font="Aller", weight = 700) %>%
image_compose(gh_logo, gravity="West", offset = "+50+40") %>%
color="#0d4448", size=60, font="Aller", weight = 700) |>
image_compose(gh_logo, gravity="West", offset = "+50+40") |>
image_annotate("yonicd/details", gravity="West", location="+110+45",
size=50, font="Ubuntu Mono") %>%
size=50, font="Ubuntu Mono") |>
image_border_ghcard("#ede6f2")

gh %>%
gh |>
image_write(here::here("input", "details_ghcard.png"))
2 changes: 1 addition & 1 deletion man/details.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions man/pipe.Rd

This file was deleted.

Loading

0 comments on commit 04f4867

Please sign in to comment.