Skip to contents

R Package For General Bits and Bobs of Code

Author: Mark C. Eisler

eMail:

ORCID = 0000-0001-6843-3345

Example

This is a basic example which shows you how to use a few of the BitsnBobs functions: –

library(BitsnBobs)
## Use dplyr::starwars data
starwars <- dplyr::starwars

## Extract and sort unique values of the "homeworld" column in the starwars data
starwars |> wizard(homeworld)
## …and paste them into a character string.
starwars |> wizard(homeworld, ", ")

## Find strings containing the pattern "Darth" in the starwars "name" column
starwars |> detective(name, .pattern = "Darth")
## Modify strings containing the pattern "Darth" but not "Vader" in the "name" column
starwars |> detective(name, .pattern = "Darth", .exclude = "Vader") <- "Darth The First"
## Find strings containing the pattern "Darth" in the revised data in descending order
starwars |> detective(name, .pattern = "Darth", .arrange_by = desc(name))

## Create a "retrieval" function for the starwars data frame using "name" as index
retrieve_starwars <- retriever(starwars, name)
## … and retrieve selected columns for row(s) specified using the "name" index
retrieve_starwars("Luke Skywalker", ends_with("color"), homeworld)

## Create a replacement function using "name" as index
`replace_at_name<-` <- remplacer(name)
## Replace the value in the "homeworld" column for row(s) specified using the "name" index
starwars |> replace_at_name("Luke Skywalker", homeworld) <- "Mimiland"
## Retrieve selected columns for row(s) specified using the "name" index
retrieve_starwars("Luke Skywalker", ends_with("color"), homeworld)