---
title: "Announcing the Packages Hexwall"
subtitle: "Interactive exploration of the Clinical Trials CRAN Task View"
author: "Yoni"
date: "2024-03-05"
categories: [news, R]
image: hexwall_logo.svg
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
  message = NA,
  echo = FALSE
  )
```

```{r}
library(svgpatternsimple)
library(minisvg)
library(gt)
```


```{r hexwall logo, eval = FALSE}

logo <- svg_doc(width = 200, height = 200)
hex_pattern <- create_pattern_hex(id = 'p5' , fill_fraction = 0.1, colour = "#345678")

logo$defs(hex_pattern)

len     <- 100
angles  <- (seq(0, 360, 60) + 90) * pi/180
xs      <- round(len * cos(angles) + 100, 2)
ys      <- round(len * sin(angles) + 100, 2)
hex     <- stag$polygon(id = 'hex', xs = xs, ys = ys)
hex$update(stroke = '#c0c0c0', fill = hex_pattern)
logo$append(hex)

logo$show()
logo$save("blog/hexwall_post/hexwall_logo.svg")
```

```{r get views}
# Download Views binary file from CRAN
tmpfile <- tempfile()
repo <- 'https://cloud.r-project.org'
download.file(paste(repo, "src/contrib/Views.rds", sep = "/"), destfile = tmpfile)

# Get packages on the task view
all_Views <- readRDS(tmpfile)
unlink(tmpfile)
```

## CRAN task views

The [CRAN tasks views](https://cran.r-project.org/web/views/) are an indispensable resource of information for discovering which R packages are the right ones for specific tasks. There are `r length(all_Views)` of task views spanning a variety of topics. Each topic has subject matter experts who maintain the lists of packages. Below is a summary table of all the CRAN task views showing the topic (with a link to it), the maintainers, the date it was last updated and the number of packages in the task view.

```{r summary table}
purrr::map_df(all_Views, function(x){
    tibble::tibble(
        topic = glue::glue("<a href = '{x$source}'>{x$topic}</a>"),
        maintainers = x$maintainer, 
        last_update = x$version, 
        n_pkg = nrow(x$packagelist)
    ) |>
    dplyr::mutate(topic = purrr::map(topic, gt::html))
}) |>
gt::gt() |>
gt::tab_header(title = 'CRAN Task Views Summary Table') |>
gt::cols_label(
    topic = 'Topic',
    maintainers = 'Maintainers',
    last_update = 'Last Updated',
    n_pkg = 'Number of Packages'
) |>
gt::tab_options(
    container.height = '300px' 
)

```


## Clinical Trials task view

We are going to focus on the **`r all_Views[[6]]$topic` task view** maintained by `r all_Views[[6]]$maintainer`. Below is the task view itself. The task view layout has in the header summary information of the task view and the body contains the packages. They are categorized into sections: Design and Monitoring, Design and Analysis, Analysis for Specific Designs, Analysis in General and Meta Analysis. 

The next area of the layout lists which packages are "Core" packages to the task view, which are "Regular" and which are archived on CRAN. There is a section listing related links that can include either noteworthy packages on GitHub or topic-specific references. Finally, there are links to other task views that the packages may intersect. 

Each package listed in the task view has a link to the CRAN homepage of the package and a short description of what task the package intends to solve. 

```{r}
htmltools::tags$iframe(
    id = "ctv", width = "100%", height = "300px",
    src = "https://cran.r-project.org/web/views/ClinicalTrials.html"
)
```

## The Hexwall

This resource has a wealth of information for the newly initiated R user and also the expert R user in keeping up to date with the latest packages in the subject.

This being said the layout of the task view may be a bit daunting. It is strictly text and only gives a short description of each package. To fully understand what the package does and the health of the package the reader needs to click on the package link and then conduct more research to get relevant information.

This can be for many an entry cost that limits and inhibits the full utility of the task view and the hard work the maintainers do to keep it up to date.

To remedy these issues we have developed a [new layout](https://www.openstatsware.org/hexwall) to navigate the packages listed in the task view. It is an interactive layout with packages represented as hex images, where we use the package hex sticker when there is one and a general hexagon for packages without. When the user clicks on a hex sticker the CRAN package homepage is displayed on the left-hand side.

```{r}
htmltools::tags$iframe(
    id = "hexwall", width = "100%", height = "300px",
    src = "https://www.openstatsware.org/hexwall"
)
```

## Next Steps

This is the first release of the hexwall layout and we plan to iterate and add more useful information to it. We invite users to give us feedback on the layout and what information they would like to see added to it that will make your research into which packages to use to complete a task more informative and efficient.
