### Rpackage.c: Load packages and run examples Source: https://github.com/r-devel/r-svn/blob/main/tests/Embedding/index.html This C application demonstrates loading R packages (ctest, mva) and running their examples within an embedded R context. The packages must be linked against libR.so. ```c #include #include #include int main(int argc, char **argv) { SEXP call; Rf_initEmbeddedR(argc, argv); /* Load the ctest package */ { PROTECT(call = Rf_lang2(Rf_install("library"), Rf_mkString("ctest"))); Rf_eval(call, R_GlobalEnv); UNPROTECT(1); } /* Load the mva package */ { PROTECT(call = Rf_lang2(Rf_install("library"), Rf_mkString("mva"))); Rf_eval(call, R_GlobalEnv); UNPROTECT(1); } /* Run examples for ctest */ { PROTECT(call = Rf_lang2(Rf_install("example"), Rf_mkString("ctest"))); Rf_eval(call, R_GlobalEnv); UNPROTECT(1); } /* Run examples for mva */ { PROTECT(call = Rf_lang2(Rf_install("example"), Rf_mkString("mva"))); Rf_eval(call, R_GlobalEnv); UNPROTECT(1); } Rf_endEmbeddedR(0); return 0; } ``` -------------------------------- ### Viewport Tree Navigation Example Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Demonstrates using pushViewport, grid.rect, and vpPath for drawing within a viewport tree. The 'vp' argument accepts a vpPath to specify the drawing location. ```R pushViewport(viewport(w=.5, h=.5, name="A")) grid.rect() pushViewport(viewport(w=.5, h=.5, name="B")) grid.rect(gp=gpar(col="grey")) upViewport(2) grid.rect(vp="A", gp=gpar(fill="red")) grid.rect(vp=vpPath("A", "B"), gp=gpar(fill="blue")) ``` -------------------------------- ### Viewport and Grid Layout Example Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Shows how to set up viewports with a grid layout and draw points, axes, and labels within specific layout positions. Demonstrates scaling with xscale and yscale. ```R push.viewport(viewport(layout=grid.layout(1, 2))) push.viewport(viewport(layout.pos.col=1)) push.viewport(viewport(w=.8, h=.8, xscale=c(10,0))) grid.points(1:10, 1:10/11) grid.xaxis() grid.yaxis() pop.viewport(2) push.viewport(viewport(layout.pos.col=2)) push.viewport(viewport(w=.8, h=.8, yscale=c(10,0))) grid.points(1:10/11, 1:10) grid.xaxis() grid.yaxis() pop.viewport(3) ``` -------------------------------- ### Basic Grid Rectangle Example Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Demonstrates how to draw a rectangle using the grid package with specified coordinates and dimensions in native units. ```R library(grid) x11() grid.rect(x=10, y=10, width=10, height=10, default.units="native") ``` -------------------------------- ### Grid Layout Matrix Respect Example Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Demonstrates a bug fix related to layout matrix respect, showing how a specific cell (1,2) should be respected instead of another (1,3). ```R lt.resp <- matrix(0, 2, 3) lt.resp[1,2] <- 1 grid.show.layout(grid.layout(2, 3, respect = lt.resp)) ``` -------------------------------- ### Summing Units in Grid Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Shows how to use the sum() method for units to combine multiple units, with an example of adding units of different types. ```R grid.rect(w=sum(unit(c(.25,.25), "npc"))) ``` ```R grid.rect(w=sum(unit(c(.25,.25), "npc"), unit(1, "cm")), border="red") ``` -------------------------------- ### Viewport Masking Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Example of using the new 'mask' argument in viewport(). The mask can be 'none', 'inherit', or a grob that defines a mask. ```R viewport(mask="none") vp = viewport(mask="inherit") vp = viewport(mask=grob()) ``` -------------------------------- ### Get R Home Directory Source: https://github.com/r-devel/r-svn/blob/main/src/unix/system.txt Retrieves the R home directory as a string. ```c char *R_HomeDir(void) ``` -------------------------------- ### KaTeX Starter HTML Template Source: https://github.com/r-devel/r-svn/blob/main/doc/html/katex/README.md A basic HTML template demonstrating how to include KaTeX CSS and JavaScript, including the auto-render extension for automatic math rendering. ```html ... ``` -------------------------------- ### Navigate Viewports with Depth Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt downViewport() now reports the depth it navigated to find a viewport, which can be used with upViewport() to return to the starting point. ```R depth <- downViewport("vpname") upViewport(depth) ``` -------------------------------- ### Initialization Actions Source: https://github.com/r-devel/r-svn/blob/main/src/unix/system.txt Functions for loading initial system and user data into R. ```c void R_InitialData(void) FILE* R_OpenInitFile(void) FILE* R_OpenLibraryFile(char *file) FILE* R_OpenSysInitFile(void) FILE* R_OpenSiteFile() ``` -------------------------------- ### Choose File Source: https://github.com/r-devel/r-svn/blob/main/src/unix/system.txt Allows the user to choose a file. On command-line systems, it prompts the user; on GUI platforms, it opens a dialog box. ```c int R_ChooseFile(int new, const char *buf, int len) ``` -------------------------------- ### Grid Text Label Conversion Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Shows an example where grid.rect uses grid.text to define its width, demonstrating the conversion of the label argument to a string. ```R grid.rect(w=unit(1, "grobwidth", data=grid.text(5))) ``` -------------------------------- ### Check for Hidden File Source: https://github.com/r-devel/r-svn/blob/main/src/unix/system.txt Returns 1 if a file is considered 'hidden'. On Unix, this means the filename starts with '.'. Currently, only Unix-style visibility is implemented. ```c int R_HiddenFile(const char *file) ``` -------------------------------- ### Navigating Viewports with Return Path Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Demonstrates using the invisible return value of upViewport to capture the path, allowing for navigation back to the original viewport using downViewport. ```R upPath <- upViewport(n) ... downViewport(upPath) ``` -------------------------------- ### Control New Page Prompting Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt The grid.prompt() function allows control over whether the user is prompted before starting a new page of output, replacing the par(ask) behavior. ```R grid.prompt(prompt = TRUE) ``` -------------------------------- ### Viewport Clipping with Paths Source: https://github.com/r-devel/r-svn/blob/main/src/library/grid/inst/doc/changes.txt Demonstrates how a viewport's 'clip' argument can now accept a path (from as.path()), defining a clipping path and allowing specification of the fill rule for that path. ```R viewport(clip=as.path()) ```