MyNixOS website logo
Description

Convert Files that Use 'palmerpenguins' to Work with 'datasets'.

From 'R' 4.5.0, the 'datasets' package includes the penguins and penguins_raw data sets popularised in the 'palmerpenguins' package. 'basepenguins' takes files that use the 'palmerpenguins' package and converts them to work with the versions from 'datasets' ('R' >= 4.5.0). It does this by removing calls to library(palmerpenguins) and making the necessary changes to column names. Additionally, it provides helper functions to define new files paths for saving the output and a directory of example files to experiment with.

basepenguins

R-CMD-check Codecov testcoverage CRANstatus

Convert scripts that use the palmerpenguins package to use the versions of the penguins and penguins_raw datasets that are available in R ≥ 4.5.0.

The Palmer Penguins datasets have become very popular in the R community, especially in educational contexts, and as an alternative to the iris dataset. Now that penguins and penguins_raw are in datasets (R ≥ 4.5.0), they are more widely available and easier to get started with, especially for new R users and for use in teaching.

The version of penguins in datasets (R ≥ 4.5.0) has some shorter variable names than the palmerpenguins equivalent (e.g. bill_len instead of bill_length_mm), for more compact code and data display. It does mean, however, that for those wanting to use R’s version of penguins, it isn’t simply a case of removing the call to library(palmerpenguins) or replacing palmerpenguins with datasets in data("penguins", package = "palmerpenguins") and the script still running. The basepenguins package takes care of converting files by removing the call to palmerpenguins and making the necessary conversions to variable names, ensuring that the resulting scripts still run using the datasets versions of penguins and penguins_raw.

Installation

basepenguins is available on CRAN:

install.packages("basepenguins")

Or get the development version from R-universe:

install.packages("basepenguins", repos = "https://ellakaye.r-universe.dev")

Converting a file

If a file is ‘convertible’, i.e. it contains library(palmerpenguins) or data("penguins", package = "palmerpenguins") (with any style of quotes), and has one of a specified set of extensions (by default "R", "r", "qmd", "rmd", "Rmd"), then converting it will do the following:

  • Replace library(palmerpenguins) (or same with palmerpenguins in quotes) with the empty string""
  • Replace data("penguins", package = "palmerpenguins") (with any style of quotes) with data("penguins", package = "datasets")
  • Replace variable names:
    • bill_length_mm -> bill_len
    • bill_depth_mm -> bill_dep
    • flipper_length_mm -> flipper_len
    • body_mass_g -> body_mass
  • Replace ends_with("_mm") with starts_with("flipper_"), starts_with("bill_")

Here, we simply show the ‘before-and-after’ when converting a single file. For a more extensive guide to using the package, see the Get Started vignette, vignette("basepenguins").

library(basepenguins)

Get and see an example file provided by the package (adapted from a section of the palmerpenguinsGet Started vignette):

penguins_file <- example_files("penguins.R")
cat(readLines(penguins_file), sep = "\n")
#> library(palmerpenguins)
#> library(ggplot2)
#> library(dplyr)
#> 
#> # exploring scatterplots
#> penguins |>
#>   select(body_mass_g, ends_with("_mm")) |>
#>   ggplot(aes(x = flipper_length_mm, y = body_mass_g)) +
#>   geom_point(aes(color = species, shape = species), size = 2) +
#>   scale_color_manual(values = c("darkorange", "darkorchid", "cyan4"))

Then, convert the file (saving it to a new file) and see the new script:

convert_files(penguins_file, "penguins_converted.R")
#> - ends_with("_mm") replaced on line 7 in penguins_converted.R
#> - Please check the changed output files.
cat(readLines("penguins_converted.R"), sep = "\n")
#> 
#> library(ggplot2)
#> library(dplyr)
#> 
#> # exploring scatterplots
#> penguins |>
#>   select(body_mass, starts_with("flipper_"), starts_with("bill_")) |>
#>   ggplot(aes(x = flipper_len, y = body_mass)) +
#>   geom_point(aes(color = species, shape = species), size = 2) +
#>   scale_color_manual(values = c("darkorange", "darkorchid", "cyan4"))

Converting multiple files or a directory

There are four functions in basepenguins to convert mulitple files. In each case, the default extensions (i.e. file types to convert) are "R", "r", "qmd", "rmd", "Rmd". If input contains non-convertible files (i.e. without the specified extensions or without reference to palmerpenguins), they will be copied unmodified to their new output location in convert_files() and convert_dir(), or left untouched by convert_files_inplace() and convert_dir_inplace().

convert_files(input, output, extensions)convert an input vector of files to new output locations
convert_files_inplace(input, extensions)convert a vector of files by overwriting them
convert_dir(input, output, extensions)convert all files in input directory into a new output directory (preserving nesting structure)
convert_dir_inplace(input, extensions)convert all files in a directory by overwriting them.
Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows