Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ netplot\._.*\.tar\.gz
^Rplots\.pdf$
^doc$
^Meta$
^AGENTS\.md$
^\.devcontainer$
^\.vscode$
4 changes: 4 additions & 0 deletions .devcontainer/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"r.plot.useHttpgd": true,
"r.alwaysUseActiveTerminal": true
}
19 changes: 19 additions & 0 deletions .devcontainer/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ghcr.io/rocker-org/devcontainer/r-ver:4.5

# Architecture-specific variable (built in Docker BuildKit)
ARG TARGETARCH

# Install quarto-cli and the orange-book extension
RUN wget https://github.com/quarto-dev/quarto-cli/releases/download/v1.9.35/quarto-1.9.35-linux-${TARGETARCH}.deb && \
dpkg -i quarto-1.9.35-linux-${TARGETARCH}.deb && \
rm quarto-1.9.35-linux-${TARGETARCH}.deb

# Adding R packages
RUN install2.r --error knitr rmarkdown markdown igraphdata intergraph \
ggraph gridGraphics ggplot2 gridExtra gridBase magrittr tinytest \
sna igraph network

RUN apt-get update && apt-get install --no-install-recommends -y \
libglpk-dev

CMD ["bash"]
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.1.0",
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671",
"integrity": "sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671"
}
}
}
42 changes: 42 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "netplot",
"build": {
"dockerfile": "Containerfile"
},
"customizations": {
"vscode": {
"extensions": [
"reditorsupport.r",
"rdebugger.r-debugger",
"quarto.quarto",
"tianyishi.rmarkdown",
"github.vscode-github-actions",
"ms-vscode.live-server"
]
}
},
"mounts": [
// Mount the .vscode configuration into the container
"source=${localWorkspaceFolder}/.devcontainer/.vscode,target=/workspaces/${localWorkspaceFolderBasename}/.vscode,type=bind,consistency=cached"
],
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.1.0"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

- uses: r-lib/actions/setup-pandoc@v2

Expand Down Expand Up @@ -68,8 +68,14 @@ jobs:
check-dir: '"check"'
error-on: '"warning"'

# Building the tar.gz file for ubuntu-latest and release R version
- name: Build package
if: ${{ matrix.config.os == 'ubuntu-latest' && matrix.config.r == 'release' }}
run: |
R CMD build .

# Upload the built package as an artifact
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v7
if: ${{ matrix.config.os == 'ubuntu-latest' && matrix.config.r == 'release' }}
with:
name: ${{ matrix.config.os }}-pkg
Expand Down
90 changes: 75 additions & 15 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,86 @@
name: netplot website
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

on: [push, pull_request]
name: pkgdown

env:
cntr: usccana/netplot:release
# Sets permissions of the GITHUB_TOKEN
permissions:
contents: read
pages: write
id-token: write
pull-requests: write
actions: read

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: Ubuntu-latest

runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-pandoc@v2

- name: Container
run: docker pull ${cntr}
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Building website
run: docker run --rm -i -v ${PWD}:/home/mnt -w /home/mnt ${cntr} Rscript -e 'system("R CMD INSTALL .");pkgdown::build_site(install=FALSE)'
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
# Upload artifact for GitHub Pages deployment (only for pushes to main/master)
- name: Upload Pages artifact
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
uses: actions/upload-pages-artifact@v5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
path: docs

# Upload artifact for PR preview (only for pull requests)
- name: Upload PR artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v7
with:
name: pkgdown-site
path: docs

# Post comment with link to artifact on PRs
- name: Post artifact link to PR
if: github.event_name == 'pull_request'
uses: CDCgov/cfa-actions/post-artifact@v1.2.0
with:
artifact-name: pkgdown-site
gh-token: ${{ secrets.GITHUB_TOKEN }}
message: 'Thank you for your contribution @${{ github.actor }} :rocket:! The pkgdown site preview is ready for review :point_right: [Download here]({ artifact-url }) :point_left:!'

# Deployment job - only runs on pushes to main/master
deploy:
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
11 changes: 11 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# What is this project about

This is an R package that uses the `grid` package to create network plots. The package is focused on aesthetics and tries to provide an interface that has a lower footprint in dependencies than other packages, leveraging existing base R packages.

## Development workflow and preferences

- We follow the tinyverse style for code (so minimal dependencies, but still using `roxygen2` for documentation).

- For testing the package, we use `tinytest`.

- For checking the R package, we use `devtools::check()`, and for documenting we call `devtools::document()`.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Depends:
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.3
Roxygen: list(markdown = TRUE)
Imports:
graphics,
Expand Down
56 changes: 11 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
VERSION:=$(shell Rscript -e 'x<-readLines("DESCRIPTION");cat(gsub(".+[:]\\s*", "", x[grepl("^Vers", x)]))')
PKGNAME:=$(shell Rscript -e 'x<-readLines("DESCRIPTION");cat(gsub(".+[:]\\s*", "", x[grepl("^Package", x)]))')
README.md: README.qmd
quarto render README.qmd

install: build
cd ../ && \
R CMD INSTALL $(PKGNAME)_$(VERSION).tar.gz

$(PKGNAME)_$(VERSION).tar.gz:
cd ../ && R CMD build $(PKGNAME)/
.PHONY: build check install checkfull checkv clean man docker checkd

build: $(PKGNAME)_$(VERSION).tar.gz
build: docs
R CMD build .

inst/NEWS: NEWS.md
Rscript -e "rmarkdown::pandoc_convert('NEWS.md', 'plain', output='inst/NEWS')"&& \
head -n 80 inst/NEWS
check: docs
Rscript -e "devtools::check()"

README.md: README.Rmd
Rscript -e 'rmarkdown::render("README.Rmd")'
install: docs
Rscript -e "devtools::install()"

.PHONY: checfull checkv clean

check: $(PKGNAME)_$(VERSION).tar.gz
R CMD check --no-vignettes --no-manual $(PKGNAME)_$(VERSION).tar.gz

checkfull: R/*.R inst/NEWS README.md
R CMD build . \&&
R CMD check --as-cran $(PKGNAME)_$(VERSION).tar.gz

checkv: $(PKGNAME)_$(VERSION).tar.gz
R CMD check --as-cran --use-valgrind $(PKGNAME)_$(VERSION).tar.gz

clean:
cd ../ && \
rm -rf $(PKGNAME).Rcheck $(PKGNAME)_$(VERSION).tar.gz

.PHONY: man docker
man: R/*
Rscript --vanilla -e 'roxygen2::roxygenize()'

docker:
docker run -v$(pwd):/pkg/ -w/pkg --rm -i uscbiostats/fmcmc:latest make check

checkd:
apt update && \
tlmgr install amsmath && \
install2.r igraph gridGraphics gridBase gridExtra magrittr tinytest sna \
ggraph rmarkdown knitr intergraph igraphdata pkgdown markdown && \
apt install libglpk-dev --no-install-recommends -y && \
R CMD build . && \
R CMD check --no-manual $(PKGNAME)_$(VERSION).tar.gz
docs:
Rscript -e "devtools::document()"
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# netplot 0.3-0

* `nplot.network()` now uses the `"weight"` edge attribute for `edge.width`
by default (like `nplot.igraph()` already did), so edge widths reflect edge
weights instead of being drawn uniformly. `edge.width` values are also
explicitly re-applied to each edge grob after color post-processing to keep
the drawn line widths robust. Closes #17.

* `edge.width.range`, `vertex.size.range`, and `vertex.label.range` now accept
`NULL` to suppress scaling and use the supplied values as-is.

* Fixed `vertex.rot`, which was truncated to an integer and so ignored
fractional (radian) rotations; the named `"square"` shape orientation was
corrected as well.

* `edge.line.lty` is now validated to be length 1 or one value per plotted
edge, and is subset correctly when `sample.edges` drops edges.

* Invalid arguments passed to `nplot()` now raise an error.

* Figures with legends are not drawn twice.
Expand Down
5 changes: 4 additions & 1 deletion R/geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
#' @param size Numeric vector. Size of the node (radious).
#' @param rel Numeric vector of length 3. Relative size for the minimum and maximum
#' of the plot, and curvature of the scale. The third number is used as `size^rel[3]`.
#' If `NULL`, scaling is suppressed.
#'
#' @details
#' This function is to be called after [plot.new], as it takes the parameter `usr`
#' from the
#' @noRd
rescale_size <- function(size, rel=c(.01, .05, 1)) {

if (is.null(rel))
return(size)

# Checking the rel size
if (length(rel) == 2)
rel <- c(rel, 1)
Expand Down Expand Up @@ -204,4 +208,3 @@ map_attribute_to_shape <- function(x) {
names(sides_lookup)[as.numeric(factor(x))]

}

Loading