### Programmatic Exploration with example() Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html The example() function now accepts optional 'character.only' and 'give.lines' arguments for programmatic exploration of examples. ```R example(topic, package, lib.loc, character.only, give.lines, ...) ``` -------------------------------- ### Configure, Make, and Install R Source Source: https://github.com/wch/r-source/wiki/Home Standard commands to configure, build, and install R from source. Ensure you are in the repository root before running. ```sh ./configure && make all && make install ``` -------------------------------- ### Enable R Framework Installation Source: https://github.com/wch/r-source/wiki/macOS-build-instructions Pass this flag to the configure script to install R as a framework. This is recommended for easier management on macOS. ```sh ./configure --enable-R-framework ``` -------------------------------- ### Controlling \donttest Execution in Examples Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The example() function's run.donttest argument and tools::Rd2ex()'s commentDonttest control the execution of \donttest code in help examples, with interactive use as a default condition. ```R example(..) ``` -------------------------------- ### R CMD INSTALL Options for KeepSource and Byte-Compile Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html Control package installation with `--with-keep-source` or `--without-keep-source` flags. The `--byte-compile` option enables byte-compilation during installation. ```bash R CMD INSTALL --with-keep-source R CMD INSTALL --without-keep-source R CMD INSTALL --byte-compile ``` -------------------------------- ### Grid Frame and Grob Packing Example Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt This example demonstrates a fix for a stack overflow issue that occurred during grid packing. It involves creating a grid frame and packing multiple grobs into it, which now completes without error. ```R gf <- grid.frame(layout = grid.layout(nrow=1, ncol=1), draw = FALSE) grob.rect <- grid.rect(x = 1:99/100, y = 1:99/100, h = rep(.01, 100), w = rep(.05, 100), gp = gpar(col = terrain.colors(100)), draw = FALSE) grid.pack(frame = gf, row = 1, col = 1, grob = grob.rect, draw = FALSE) grid.draw(gf) ``` -------------------------------- ### Rpackage.c: Load packages and run examples Source: https://github.com/wch/r-source/blob/trunk/tests/Embedding/index.html This C application demonstrates loading R packages (ctest and mva) and running their example functions within an embedded R context. The packages must be linked against libR.so. Ensure R is initialized. ```c #include #include #include int main(int argc, char *argv[]) { SEXP result; // Initialize R (assuming it's done elsewhere or implicitly) // Load the 'ctest' package and run its examples // This is equivalent to calling 'library(ctest); example(ctest)' in R Rf_eval(Rf_parse("library(ctest)"), R_GlobalEnv); result = Rf_eval(Rf_parse("example(ctest)"), R_GlobalEnv); // Load the 'mva' package and run its examples Rf_eval(Rf_parse("library(mva)"), R_GlobalEnv); result = Rf_eval(Rf_parse("example(mva)"), R_GlobalEnv); Rprintf("Package examples executed successfully.\n"); return 0; } ``` -------------------------------- ### R Installation Configuration Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html When R is installed, `javareconf` is used, allowing for a stable link to be supplied for JAVA_HOME during the configuration process. ```bash --disable-byte-compilation ``` -------------------------------- ### Install and Call Overridden Methods Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html Ensures methods that override previously loaded versions are correctly installed and called. ```R Methods that override ``` -------------------------------- ### Install zlib Dependency Source: https://github.com/wch/r-source/wiki/macOS-build-instructions Use Homebrew to install the zlib library and headers, which are required for building R. ```sh brew install zlib ``` -------------------------------- ### Ignore \dontrun Markup in Examples Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Use the new parameters in `example()` and `tools::Rd2ex()` to ignore `\dontrun` markup when running examples. ```R example(topic, run.dontrun = TRUE) ``` ```R tools::Rd2ex(file, run.dontrun = TRUE) ``` -------------------------------- ### Install liblzma Dependency Source: https://github.com/wch/r-source/wiki/macOS-build-instructions Use Homebrew to install the liblzma library and headers, which are required for building R. ```sh brew install xz ``` -------------------------------- ### Install R Packages with Binary and Source Options Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html Use `install.packages(type = "both")` to allow R to choose between binary and source package versions during interactive installation. R will prompt for decisions when a binary version is older or when a source package lacks a binary counterpart. ```r install.packages(type = "both") ``` -------------------------------- ### Test Installed R Packages Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The `tools::testInstalledPackage()` function can now test \dontrun\ and \donttest\ examples. Set `commentDontrun` or `commentDonttest` to `TRUE` to enable this. ```r tools::testInstalledPackage(commentDontrun = FALSE, commentDonttest = FALSE) ``` -------------------------------- ### Install Build Dependencies for R Source: https://github.com/wch/r-source/wiki/Ubuntu-build-instructions Installs necessary packages for building R from source. Ensure you have the required build dependencies before proceeding. ```sh sudo apt-get build-dep r-base sudo apt-get install subversion ccache texlive texlive-fonts-extra texlive-latex-extra ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/wch/r-source/wiki/macOS-build-instructions Install the Xcode command line tools if you encounter errors related to C compilation, as this provides necessary compilers and tools. ```sh xcode-select --install ``` -------------------------------- ### Grid layout matrix respect example Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt Demonstrates a bug in layout matrix respect where the wrong cell was being respected. This example shows the incorrect behavior that was fixed. ```R lt.resp <- matrix(0, 2, 3) lt.resp[1,2] <- 1 grid.show.layout(grid.layout(2, 3, respect = lt.resp)) ``` -------------------------------- ### Graphical Select.list() Checks Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html Functions using `select.list()` (like `menu()` and `install.packages()`) now check if Tk can be started on Unix-alike systems. This ensures that graphical interfaces function correctly. ```R select.list(name, ...) ``` ```R menu(choices, ...) ``` ```R install.packages(pkgs, ...) ``` -------------------------------- ### Install Packages with Specific Type Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Control the type of R package to install using the `type` argument in `install.packages()`. Use `type = "both"` to try binary packages first, then source if unavailable or outdated. Use `type = "binary"` to exclusively install binary packages. ```r install.packages(type = "both") ``` ```r update.packages(type = "binary") ``` -------------------------------- ### Fix for custom Windows installer target 'myR' Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html The custom Windows installer target 'myR' in the installer 'Makefile' now functions correctly. ```Makefile myR ``` -------------------------------- ### Grobwidth and Grobheight Unit Bug Fix Example Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt This code demonstrates a bug fix in the calculation of 'grobwidth' and 'grobheight' units. The example creates a frame with specific text units and then draws a rectangle around it, which should now fit snugly. ```R grid.newpage() # Create a frame with fontsize=6 gf <- grid.frame(layout=grid.layout(10, 10, widths=unit(rep(1, 10), "strwidth", as.list(rep("o", 10))), heights=unit(rep(1, 10), "strheight", as.list(rep("o", 10)))), gp=gpar(fontsize=6)) # Add a rect to the frame for (i in 1:10) grid.place(gf, grid.rect(gp=gpar(col="grey"), draw=FALSE), col=i, row=i) grid.draw(gf) # Now draw a rect around the frame grid.rect(width=unit(1, "grobwidth", gf), height=unit(1, "grobheight", gf)) ``` -------------------------------- ### Package Installation Dependencies Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html When installing packages, install.packages(dependencies = NA) or install.packages(dependencies = TRUE) will omit packages listed only in 'LinkingTo' for binary package installations. ```R install.packages(dependencies = value) ``` -------------------------------- ### Install Binary Package on Mac OS X Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html When installing packages on Mac OS X, use the 'install.packages()' function with a .tgz file. The function now includes sanity checks to ensure it's a binary package. ```r install.packages("pkg_version.tgz") ``` -------------------------------- ### Test Load for Sub-architectures during R CMD INSTALL Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html R CMD INSTALL now performs a test load for all compiled sub-architectures, not just the primary one. ```Shell R CMD INSTALL ``` -------------------------------- ### Grid grep with vpPath (grid 4.2.0+) Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt Example of using grid.grep() with the 'vpPath' argument to find grobs including their viewport paths. This functionality was introduced in grid 4.2.0. ```R grid.grep("path", vpPath=TRUE) ``` -------------------------------- ### Text Sizing and Positioning with Fontsize Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt Demonstrates how text is sized and positioned based on a specified fontsize. This example uses the 'lines' unit and a specific gpar fontsize. ```R grid.text("small text and small lines", y=unit(2, "lines"), gp=gpar(fontsize=6)) ``` -------------------------------- ### Checking Package Loading with library() Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html R CMD check verifies if a package can be loaded using library(pkgname, lib.loc = "somewhere") without being on the library search path. This ensures proper package installation and accessibility. ```bash R CMD check ``` -------------------------------- ### Get Information About Installed Vignettes Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The `tools::getVignetteInfo()` function provides information about installed vignettes. ```R tools::getVignetteInfo() ``` -------------------------------- ### Configure R with System Valgrind Headers Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Enable the use of system Valgrind headers during R's configuration. Note potential future incompatibilities as discussed in the R Installation and Administration manual. ```bash configure --with-system-valgrind-headers ``` -------------------------------- ### Handling Hidden Files with R CMD check --as-cran Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html R CMD check --as-cran identifies hidden files (starting with a dot) that are not essential for R CMD INSTALL or R CMD build. These files should be excluded from tarballs to maintain a clean distribution. ```bash R CMD check --as-cran ``` -------------------------------- ### HTML Starter Template for KaTeX Source: https://github.com/wch/r-source/blob/trunk/doc/html/katex/README.md Include this HTML structure to set up KaTeX rendering in a web page. It links to KaTeX's CSS and JavaScript files, including the auto-render extension for automatic math detection. ```html ... ``` -------------------------------- ### Build R from Source (Standard Procedure) Source: https://github.com/wch/r-source/wiki/Home The standard procedure for building R from source, including downloading recommended packages. ```sh # Download recommended packages tools/rsync-recommended ./configure make ``` -------------------------------- ### File Snapshot and Comparison Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The `utils` package offers `fileSnapshot()` to create directory snapshots and `changedFiles()` to compare them. ```R utils::fileSnapshot(path) ``` ```R utils::changedFiles(snapshot1, snapshot2) ``` -------------------------------- ### Navigate Viewports Up and Down Using Returned Path Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt Illustrates how to capture the path of viewports when moving up using upViewport() and then use that path to return to the original viewport with downViewport(). This enables precise navigation within the viewport hierarchy. ```R upPath <- upViewport(n) up... downViewport(upPath) ``` -------------------------------- ### Using `pkg-config` for JPEG Linking Flags Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Explains that `configure` now uses `pkg-config` to find linking flags for `jpeg` if available, accommodating recent `jpeg` versions. ```Shell configure ``` -------------------------------- ### Rd Section Creation with Sexpr in R Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Demonstrates the correct usage of \Sexpr[stage=install]{..} for creating Rd sections without warnings during R CMD check. ```r \Sexpr[stage=install]{..} ``` -------------------------------- ### Efficiently Combining exists() and get() Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The new get0() function combines the functionality of exists() and get() into a single, more efficient call. ```R get0() ``` -------------------------------- ### Using -lz for ZLIB_LIBS Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html When compiling on Windows, it's recommended to use `-lz` instead of relying on an external `libz.a` for `ZLIB_LIBS` in `src/Makevars.win`. This simplifies the build process. ```makefile # It would be simpler to use -lz instead. ``` -------------------------------- ### R Initialization Functions Source: https://github.com/wch/r-source/blob/trunk/src/unix/system.txt Functions to load initial system and user data into R. ```c void R_InitialData(void) ``` ```c FILE* R_OpenInitFile(void) ``` ```c FILE* R_OpenLibraryFile(char *file) ``` ```c FILE* R_OpenSysInitFile(void) ``` ```c FILE* R_OpenSiteFile() ``` -------------------------------- ### Initialization and Termination Actions Source: https://github.com/wch/r-source/blob/trunk/src/unix/system.txt Functions related to R's startup, data loading, environment management, and shutdown. ```APIDOC ## R_InitialData ### Description Loads the initial system and user data into R. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## R_OpenInitFile ### Description Opens the initial system configuration file. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## R_OpenLibraryFile ### Description Opens a library file specified by its name. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters #### Path Parameters - **file** (char *) - Required - The name of the library file to open. ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## R_OpenSysInitFile ### Description Opens the system initialization file. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## R_OpenSiteFile ### Description Opens the site-specific configuration file. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## R_RestoreGlobalEnv ### Description Restores the user's global environment from storage. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## R_SaveGlobalEnv ### Description Saves the user's global environment to storage. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## R_CleanUp ### Description Invokes actions that occur at system termination. Can optionally save the workspace and control whether to run last commands. ### Method N/A (Function signature) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Graphics Device Arguments Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The `grid.show.layout()` and `grid.show.viewport()` functions include an optional `vp.ex` argument. ```R grid.show.layout(..., vp.ex = TRUE) ``` ```R grid.show.viewport(..., vp.ex = TRUE) ``` -------------------------------- ### Install R Package with Build Timestamp Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Use this option with `R CMD INSTALL` to ensure reproducible package builds by specifying a build timestamp. This feature was contributed by Dirk Eddelbuettel. ```bash R CMD INSTALL --built-timestamp=STAMP ``` -------------------------------- ### Fix R CMD INSTALL --clean option on Windows Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Resolved an issue on Windows where the --clean option for R CMD INSTALL could fail in certain scenarios. ```shell R CMD INSTALL --clean ``` -------------------------------- ### C++ standard detection flags in R installation Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Improved detection of C++98/11/14/17 flags during R installation on Unix-like systems. If CXX??STD is set, it's tried first without additional flags. ```Shell CXX??STD ``` -------------------------------- ### List Files and Directories Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html `list.files()`/`dir()` gains `include.dirs` and new `list.dirs()` function. ```APIDOC ## List Files and Directories ### Description The `list.files()` and `dir()` functions now have an `include.dirs` argument to include directories when `recursive = TRUE`. A new function, `list.dirs()`, is introduced to list all directories, including empty ones. ### Method N/A (Function argument update and new function) ### Endpoint N/A ### Parameters #### `list.files()` / `dir()` - **path** (character) - The directory path. - **pattern** (character) - Optional. A regular expression. - **all.files** (logical) - If `TRUE`, include hidden files. - **full.names** (logical) - If `TRUE`, return full paths. - **recursive** (logical) - If `TRUE`, search recursively. - **include.dirs** (logical) - If `TRUE`, include directories in the listing when `recursive = TRUE`. #### `list.dirs()` - **path** (character) - The directory path. - **recursive** (logical) - If `TRUE`, list recursively. - **full.names** (logical) - If `TRUE`, return full paths. ### Request Example ```R list.files(path = ".", recursive = TRUE, include.dirs = TRUE) list.dirs(path = ".", recursive = TRUE) ``` ### Response N/A ``` -------------------------------- ### Cex Gpar Implementation Bug Fix Example Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt This example demonstrates a bug fix in the 'cex' gpar implementation. It shows two sets of points, where the second set should have twice the radius of the first due to cex=2. ```R grid.newpage() push.viewport(viewport()) grid.points() grid.points(gp = gpar(cex = 2)) ``` -------------------------------- ### Choose File Function Source: https://github.com/wch/r-source/blob/trunk/src/unix/system.txt Prompts the user to choose a file and returns its name. Uses a dialog box on GUI platforms, command-line prompt otherwise. ```c int R_ChooseFile(int new, const char *buf, int len) ``` -------------------------------- ### R Installation with Spaces in TMPDIR Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html More of the R installation and checking process is designed to function even when TMPDIR is set to a path containing spaces. However, this configuration is not recommended, and external software may still fail. ```bash TMPDIR ``` -------------------------------- ### Check Git-SVN Initialization Source: https://github.com/wch/r-source/wiki/Home Verify that the git-svn repository has been correctly initialized. ```sh git svn info ``` -------------------------------- ### Using Shorthand for Package Dependencies Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html The tools::dependsOnPkg() function now accepts the 'all' shorthand for the dependencies argument. ```R tools::dependsOnPkg(dependencies = "all") ``` -------------------------------- ### R: Histogram Example Source: https://context7.com/wch/r-source/llms.txt Generates a histogram for visualizing the distribution of a random dataset. ```r # Histogram hist(rnorm(1000), breaks = 30, col = "lightblue", main = "Normal Distribution", xlab = "Value") ``` -------------------------------- ### Sample Integer with Replacement in R Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Illustrates the behavior of sample.int when sampling with replacement, ensuring it matches documented behavior and older R versions. ```r sample.int(2.9, *, replace=TRUE) ``` -------------------------------- ### Shallow Clone R-Source Repository Source: https://github.com/wch/r-source/wiki/Home Use a shallow clone to get only the last commit, which is quicker but limits history access. ```sh # Get just the last commit git clone https://github.com/wch/r-source.git --depth 1 ``` -------------------------------- ### Busy Indicator Function Source: https://github.com/wch/r-source/blob/trunk/src/unix/system.txt Manages actions, like cursor changes, during long computations. 'which=1' for start, 'which=0' for end. ```c void R_Busy(int which) ``` -------------------------------- ### keep.source argument for library() and require() defunct Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The keep.source argument for library() and require() is defunct. This option must be set at install time. ```R * The `keep.source` argument to `library()` and `require()` is defunct. This option needs to be set at install time. ``` -------------------------------- ### Use MIT or BSD_2_clause for license in DESCRIPTION Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html In a package's DESCRIPTION file, 'License: X11' is deprecated. Use 'MIT' or 'BSD_2_clause' instead. ```R License: X11 ``` ```R is deprecated, since it includes ‘Copyright (C) 1996 X Consortium’ which cannot be appropriate for a current **R** package. Use ‘MIT’ or ‘BSD_2_clause’ instead. ``` -------------------------------- ### Get R Home Directory Source: https://github.com/wch/r-source/blob/trunk/src/unix/system.txt Retrieves the R 'home directory' as a string. This is useful for locating configuration files or user-specific settings. ```c char *R_HomeDir(void); ``` -------------------------------- ### Locate User and Site Makevars Files Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The `tools` package offers `makevars_user()` and `makevars_site()` functions to determine the paths to user-specific and site-specific `Makevars` files, used for customizing package compilation. ```R makevars_user() ``` ```R makevars_site() ``` -------------------------------- ### Arima() Regression Coefficient Initialization Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The initialization of regression coefficients for non-degenerate differenced models in `arima()` has been improved to avoid local maxima in some examples. ```R arima(x, order = c(1,1,0), xreg = ...) ``` -------------------------------- ### Character pch in grid.points Source: https://github.com/wch/r-source/blob/trunk/src/library/grid/inst/doc/changes.txt Example of using character values for the pch argument in grid.points, a feature added in grid_0.5-1. The grid package is required. ```R grid.points(pch="+") ``` -------------------------------- ### R String Matching with grep and grepl Source: https://context7.com/wch/r-source/llms.txt Explains and demonstrates the use of 'grep' to find elements matching a pattern and 'grepl' to return a logical vector indicating matches in R character vectors. ```r # Sample text data text <- c("apple", "banana", "cherry", "date", "elderberry") # grep - return indices of matches grep("an", text) # [1] 2 (banana contains "an") # grep with value = TRUE returns matching elements grep("berry", text, value = TRUE) # [1] "elderberry" # grepl - return logical vector grepl("e", text) # [1] TRUE TRUE TRUE TRUE TRUE # Case-insensitive matching grep("APPLE", text, ignore.case = TRUE) # [1] 1 ``` -------------------------------- ### R: Box Plot Example Source: https://context7.com/wch/r-source/llms.txt Creates a box plot to compare the distribution of MPG across different cylinder counts in the `mtcars` dataset. ```r # Box plot boxplot(mpg ~ cyl, data = mtcars, main = "MPG by Cylinders", xlab = "Cylinders", ylab = "MPG", col = c("red", "green", "blue")) ``` -------------------------------- ### Fix: configure --enable-maintainer-mode without notangle Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Allows `configure --enable-maintainer-mode` to run successfully without requiring `notangle` to be installed. ```R configure --enable-maintainer-mode ``` -------------------------------- ### C: R Package Initialization Source: https://context7.com/wch/r-source/llms.txt Defines the entry point for an R package extension, registering C functions for use with the `.Call` interface. ```c // Register routines for .Call interface static const R_CallMethodDef CallEntries[] = { {"create_numeric_vector", (DL_FUNC) &create_numeric_vector, 1}, {"process_vectors", (DL_FUNC) &process_vectors, 3}, {"safe_divide", (DL_FUNC) &safe_divide, 2}, {NULL, NULL, 0} }; void R_init_mypackage(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } ``` -------------------------------- ### F77_VISIBILITY macro alternative in R package installation Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Introduces the new macro 'F_VISIBILITY' as an alternative to 'F77_VISIBILITY'. This will be the preferred form in R 3.6.0. ```Make F_VISIBILITY ``` ```Make F77_VISIBILITY ``` -------------------------------- ### .Fortran() entry point 'dqrls' removed Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The .Fortran() entry point "dqrls", unused since R 2.15.1, is no longer available. ```R * The `.Fortran()` entry point `"dqrls"` which has not been used by **R** since version 2.15.1 is no longer available. ``` -------------------------------- ### Search using help.search() in R Source: https://github.com/wch/r-source/blob/trunk/doc/html/Search.html Use this function from the R prompt to perform searches as an alternative to running the HTTP server. ```R help.search() ``` -------------------------------- ### R String Matching Positions with regexpr Source: https://context7.com/wch/r-source/llms.txt Explains how to find the starting position and length of the first match of a pattern in a string using 'regexpr'. ```r # regexpr - get match positions match_info <- regexpr("an", "banana") # [1] 2 (position of match) # attr(,"match.length") [1] 2 ``` -------------------------------- ### Correct NA propagation in cummax() for integers Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html cummax(x) now correctly propagates NA values, even when x is of type integer and starts with an NA. ```R cummax(x) ``` -------------------------------- ### Listing All Directories with list.dirs() Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html A new function list.dirs() is introduced to list all directories, including empty ones. ```R list.dirs(path = ".", recursive = TRUE, full.names = TRUE) ``` -------------------------------- ### CXX_VISIBILITY macro in R package installation Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html Introduces the 'CXX_VISIBILITY' macro, analogous to 'C_VISIBILITY', for the default C++ compiler. This addresses misuse of 'F77_VISIBILITY' for C++ code. ```Make CXX_VISIBILITY ``` ```Make C_VISIBILITY ``` -------------------------------- ### Perform K-Means Clustering in R Source: https://context7.com/wch/r-source/llms.txt Implements k-means clustering to partition data into k groups. Shows how to view results, use different algorithms, determine optimal k, and visualize clusters. ```r # Generate clustered data set.seed(42) cluster1 <- matrix(rnorm(100, mean = 0), ncol = 2) cluster2 <- matrix(rnorm(100, mean = 4), ncol = 2) cluster3 <- matrix(rnorm(100, mean = c(0, 4)), ncol = 2, byrow = TRUE) data <- rbind(cluster1, cluster2, cluster3) # Perform k-means clustering km_result <- kmeans(data, centers = 3, nstart = 25) # View results km_result$cluster # Cluster assignments km_result$centers # Cluster centroids km_result$totss # Total sum of squares km_result$withinss # Within-cluster sum of squares km_result$tot.withinss # Total within-cluster SS km_result$betweenss # Between-cluster SS km_result$size # Number of points in each cluster # Cluster assignments # [1] 3 3 3 3 3 3 3 3 3 3 ... (cluster labels for each point) # Different algorithms km_lloyd <- kmeans(data, 3, algorithm = "Lloyd") km_hartigan <- kmeans(data, 3, algorithm = "Hartigan-Wong") # Determine optimal k using elbow method wss <- sapply(1:10, function(k) { kmeans(data, k, nstart = 25)$tot.withinss }) plot(1:10, wss, type = "b", xlab = "Number of Clusters", ylab = "Within-cluster SS") # Visualize clusters plot(data, col = km_result$cluster, pch = 19) points(km_result$centers, col = 1:3, pch = 8, cex = 2) ``` -------------------------------- ### Use devAskNewPage() instead of grid.prompt() Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html The grid.prompt() function has been removed. Use devAskNewPage() for prompting for new pages. ```R * `grid.prompt()` has been removed: use `devAskNewPage()` instead. ``` -------------------------------- ### Getting Package Maintainer Information Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.2.html The `maintainer()` function provides convenient access to the name of a package's maintainer. This is useful for reporting issues or seeking support. ```R maintainer("packageName") ``` -------------------------------- ### system() Process Launch Success Check Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html system() now correctly reports failure if the system is unable to launch a process, improving reliability on some platforms. Addresses PR#15796. ```R system() ``` -------------------------------- ### New par() Parameter 'page' Source: https://github.com/wch/r-source/blob/trunk/doc/html/NEWS.3.html A new read-only `par()` parameter named 'page' indicates whether the next `plot.new()` call will start a new page. ```R par("page") ```