This is an R package that provides a lightweight interface to the AntV G2 JavaScript visualization library with a ggplot2-style API. It supports rendering in R Markdown, litedown, Shiny, and standalone HTML previews.
Project Type: R package Languages: R, JavaScript (via CDN) Size: Small repository (~15 R source files) Target Runtime: R (>= 3.5.0)
Note: R is automatically installed via .github/copilot-setup-steps.yml
when working with GitHub Copilot. For manual setup:
- R (>= 3.5.0) - available via
copilot-setup-steps.yml - R package dependencies (testit, roxygen2, xfun) - available via
copilot-setup-steps.yml
For testing on Linux manually: If not using Copilot's automated setup, install the latest R from CRAN, not from Debian/Ubuntu official repositories. Follow instructions at https://cran.r-project.org/bin/linux/ubuntu to ensure you're testing with the most recent R version that users will have.
-
Build the R package:
R CMD build . -
Install the package:
R CMD INSTALL gglite_*.tar.gz -
Run tests:
R CMD check gglite_*.tar.gz --no-manualor directly:
Rscript tests/test-all.R
- Tests use the
testitpackage - All tests should pass without errors
- Tests use the
- Tests are in
tests/testit/test-gglite.R - Use
testitpackage for assertions - Always wrap test conditions in
{}:assert('message', {}) - Use
has_error()instead oftryCatch()for error testing - Load the package with
library(gglite)before testing
Since gglite generates HTML/JavaScript visualizations, plots must be tested in headless browsers to make sure they can be rendered correctly and produce no errors in the browser console. Use tools such as Puppeteer or Playwright to open the generated HTML and verify that:
- The chart container element exists in the DOM.
- The G2 chart renders without JavaScript errors.
- No warnings or errors appear in the browser console.
Root level:
DESCRIPTION- R package metadataNAMESPACE- R package namespace (auto-generated by roxygen2)NEWS.md- ChangelogREADME.md- Package documentationexamples/- Rmd example files for each chart component
R code (R/):
gglite.R- Core: package doc, CDN URLs,g2(),encode(),annotate_df()mark.R- All 35 mark (geometry) functionsscale.R-scale_of()coordinate.R-coordinate(),coord_transpose()interact.R-interact()theme.R-theme_of()transform.R-transform_of()facet.R-facet_rect(),facet_circle()animate.R-animate()component.R-axis_of(),legend_of(),title_of(),tooltip_of(),labels_of(),style_mark(),slider_of(),scrollbar_of()render.R-build_config(),chart_html(),preview(),print.g2(),knit_print.g2(),record_print.g2(),render_shiny()
Tests (tests/):
test-all.R- Entry pointtestit/test-gglite.R- All package tests using testit framework
GitHub Actions (.github/workflows/):
R-CMD-check.yaml- Runs R CMD check on multiple platformscopilot-setup-steps.yml- Sets up the environment for Copilotgithub-pages.yml- Builds and deploys the package site via litedown
Before submitting changes:
- Run
R CMD build .to build the package - Run
R CMD check gglite_*.tar.gz --no-manualto validate - Ensure all tests pass:
Rscript tests/test-all.R - Check GitHub Actions status for multi-platform validation
- Update
NEWS.mdto document your changes
- Assignment: Use
=instead of<-for assignment - Strings: Use single quotes for strings (e.g.,
'text') - Indentation: Use 2 spaces (not 4 spaces or tabs)
- Compact code: Avoid
{}for single-expression if statements; prefer compact forms when possible - Roxygen documentation: Don't use
@descriptionor@detailsexplicitly — just write the description text directly after the title. Don't use@titleeither. - Examples: Avoid
\dontrun{}unless absolutely necessary. Prefer runnable examples that can be tested automatically. - Function definitions: For functions with many arguments, break the line
right after the opening
(, indent arguments by 2 spaces, and try to wrap them at 80-char width. - Re-wrap code: Always re-wrap the code after making changes to maintain consistent formatting and line length.
- JavaScript in R: Use
constand arrow functions (=>) in JS,type="module"for inline scripts,deferfor external scripts.
gglite does NOT use non-standard evaluation (NSE). Variables are specified
as character strings, e.g., g2(mtcars, x = 'mpg', y = 'hp').
- Use testit properly: Write all test conditions in
(), use%==%to test foridentical(), and test conditions can return vectors.assert("test description", { (length(result) %==% 3L) (file.exists(result)) })
- Always re-roxygenize: Run
roxygen2::roxygenize()after changing any roxygen documentation to update man files - MANDATORY: R CMD check before EVERY commit: You MUST run
R CMD checksuccessfully before submitting ANY code changes. - MANDATORY: Wait for CI to be green: After pushing code, you MUST wait for GitHub Actions CI to complete successfully before claiming the task is done.
- Bump version in PRs: Bump the patch version number in DESCRIPTION once per PR (on the first commit or when you first make changes), not on every commit to the PR
- NEVER BREAK CI: Breaking CI is completely unacceptable. If CI fails, you must immediately fix it.
- Never commit binary files: Avoid version-controlling binary files, especially automatically generated ones.
- Testing: Use testit assertions with proper error handling
- Update NEWS.md: When making changes, make sure to update
NEWS.mdaccordingly to document what changed. The first heading in NEWS.md always represents the dev version and must be of the form# PKG x.ywhere PKG is the package name and x.y is the next version to be released to CRAN (note: x.y, not x.y.0). Usually y is bumped from the current minor version, e.g., if the current dev version is 1.8.3, the next CRAN release is expected to be 1.9.
The main entry point is g2() which creates a chart object, then pipe
operators (|>) chain mark, scale, coordinate, interaction, theme, and
component functions:
g2(mtcars, x = 'mpg', y = 'hp') |>
mark_point() |>
scale_of('x', type = 'log') |>
theme_of('dark') |>
title_of('Motor Trend Cars')