Title: | Shorten Function Names of Functions in Another Package and Create an Index to Make Them Accessible |
---|---|
Description: | When creating a package, authors may sometimes struggle with coming up with easy and straightforward function names, and at the same time hoping that other packages do not already have the same function names. In trying to meet this goal, sometimes, function names are not descriptive enough and may confuse the potential users. The purpose of this package is to serve as a package function short form generator and also provide shorthand names for other functions. Having this package will entice authors to create long function names without the fear of users not wanting to use their packages because of the long names. In a way, everyone wins - the authors can use long descriptive function names, and the users can use this package to make short functions names while still using the package in question. |
Authors: | Obinna Obianom |
Maintainer: | Obinna Obianom <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2 |
Built: | 2024-11-01 02:52:52 UTC |
Source: | https://github.com/oobianom/r2shortcode |
A very simple and short algorithm to choose a short name based on a given name
chooseShortName( fullname = stop("Invalid string name entered."), withPrefix = NULL, withSuffix = NULL, envir = NULL, silent = FALSE )
chooseShortName( fullname = stop("Invalid string name entered."), withPrefix = NULL, withSuffix = NULL, envir = NULL, silent = FALSE )
fullname |
The name you intend to shorten |
withPrefix |
Prefix to include in front of the new short name |
withSuffix |
Suffix to include in front of the new short name |
envir |
The environment where to store the name |
silent |
Return response at the end of evaluations? |
Short forms of functions
long_function_name <- 'longFunctionCall' short_function_name <- chooseShortName(long_function_name) short_function_name # the result should "lFC"
long_function_name <- 'longFunctionCall' short_function_name <- chooseShortName(long_function_name) short_function_name # the result should "lFC"
Beware that by clearing all stored names, you may inadventently duplicate new shortnames
clearStoredNames(w = "all")
clearStoredNames(w = "all")
w |
what to clear |
empty stores for chosen name
nametostore = "ujuo" storeChosenName(nametostore) #store the chosen name nameAlreadyExists(nametostore) #check if the chosen name now exists in store clearStoredNames("all") #clear storage of all names nameAlreadyExists(nametostore) #check if the chosen name now exists in store, it should not
nametostore = "ujuo" storeChosenName(nametostore) #store the chosen name nameAlreadyExists(nametostore) #check if the chosen name now exists in store clearStoredNames("all") #clear storage of all names nameAlreadyExists(nametostore) #check if the chosen name now exists in store, it should not
This will discard all shorthand functions created and delete them from stores as well. Good if you inadvertently shorthand a package.
discardShortcodes( pkg, reflib = options()$.funCNamesPkgReference, response = TRUE )
discardShortcodes( pkg, reflib = options()$.funCNamesPkgReference, response = TRUE )
pkg |
package name |
reflib |
reference library, preferrably leave unentered |
response |
TRUE or FALSE, return a response upon completion |
unloads short function names
pkgName = 'quickcode' shortenPkg(pkgName) discardShortcodes(pkgName)
pkgName = 'quickcode' shortenPkg(pkgName) discardShortcodes(pkgName)
Evaluates if a specified string contains special characters
hasSpecialCharacters(string)
hasSpecialCharacters(string)
string |
The string to evaluate |
TRUE or FALSE
strToTest1 <- 'obi_%_good_^you' strToTest2 <- 'obigoodyou' hasSpecialCharacters(strToTest1) hasSpecialCharacters(strToTest2)
strToTest1 <- 'obi_%_good_^you' strToTest2 <- 'obigoodyou' hasSpecialCharacters(strToTest1) hasSpecialCharacters(strToTest2)
Simply change if there is any uppercase letter in a string
hasUpperCase(string)
hasUpperCase(string)
string |
the string to evaluate |
TRUE or FALSE if the string has an upper case letter
strToTest1 <- 'obiWentToSchool' strToTest2 <- 'obiwenttoschool' hasUpperCase(strToTest1) hasUpperCase(strToTest2)
strToTest1 <- 'obiWentToSchool' strToTest2 <- 'obiwenttoschool' hasUpperCase(strToTest1) hasUpperCase(strToTest2)
Access help for all functions including any newly created shorthand functions
help(functionName, package = NULL)
help(functionName, package = NULL)
functionName |
function name to search for |
package |
package name containing the function. Leave unentered if this is a shorthand function |
Documentation for function
pkgname <- 'qpdf' #pacakge name shortenPkg(pkgname,TRUE) #shorten the package index(pkgname) #index the package functions shortened help('qpd.pl') #choose a function name and find help
pkgname <- 'qpdf' #pacakge name shortenPkg(pkgname,TRUE) #shorten the package index(pkgname) #index the package functions shortened help('qpd.pl') #choose a function name and find help
This function will provide you the list of shorthand functions created for a package
index(pkg = stop("Enter a package name to index"))
index(pkg = stop("Enter a package name to index"))
pkg |
The package name |
List of long and short forms of particular functions
if(interactive()){ pkgname <- 'qpdf' shortenPkg(pkgname,TRUE) index(pkgname) }
if(interactive()){ pkgname <- 'qpdf' shortenPkg(pkgname,TRUE) index(pkgname) }
Simply, test if a string is uppercase and return TRUE or FALSE
isUpperCase(string)
isUpperCase(string)
string |
The string to evaluate |
TRUE or FALSE if the string is all upper case
strTest1 <- 'OBI' strTest2 <- 'obiO' isUpperCase(strTest1) isUpperCase(strTest2)
strTest1 <- 'OBI' strTest2 <- 'obiO' isUpperCase(strTest1) isUpperCase(strTest2)
Evaluates if a name has already been saved by the r2shortcode. Keep in mind that if you previously used the clear function, previously saved names will be cleared
nameAlreadyExists(name)
nameAlreadyExists(name)
name |
The name to lookup |
TRUE or FALSE
nameToCheck <- 'Obinna' nameAlreadyExists(nameToCheck)
nameToCheck <- 'Obinna' nameAlreadyExists(nameToCheck)
Carries out a search on the already used shorthand function names and if the new name does not exist, it saves it
searchNameSaveName(withPrefix = NULL, strN.complete, withSuffix = NULL)
searchNameSaveName(withPrefix = NULL, strN.complete, withSuffix = NULL)
withPrefix |
Provide the prefix to use for the function name, could use NULL |
strN.complete |
Provide the function name to search for, and save if feasible |
withSuffix |
Provide the suffix to use for the function name, could use NULL |
Concatenate of search and a boolean
nameToCheck <- 'ObiObianom' searchNameSaveName(strN.complete= nameToCheck) searchNameSaveName(strN.complete= nameToCheck)
nameToCheck <- 'ObiObianom' searchNameSaveName(strN.complete= nameToCheck) searchNameSaveName(strN.complete= nameToCheck)
This will create shorthand functions for functions in a package. This function brings together most functions in this package.
shortenPkg(pkg, addPrefix = TRUE, silent = FALSE, num.prefix = 3)
shortenPkg(pkg, addPrefix = TRUE, silent = FALSE, num.prefix = 3)
pkg |
package name |
addPrefix |
should prefix be added to the new names, TRUE or FALSE. Prefix will by default be first 3 letters of the package name |
silent |
return messages at the end of evaluation, TRUE or FALSE |
num.prefix |
if you specify to addPrefix, how many letters will you like to add? |
short function names for all the functions in the package
pkg <- 'qpdf' shortenPkg(pkg,FALSE,TRUE)
pkg <- 'qpdf' shortenPkg(pkg,FALSE,TRUE)
When all else passes, store this particular name in memory
storeChosenName(name)
storeChosenName(name)
name |
The chosen name to store |
store the chosen name in storage variable
nameStore <- 'ObiStore1' storeChosenName(nameStore)
nameStore <- 'ObiStore1' storeChosenName(nameStore)
Access help for all functions including any newly created shorthand functions
whatis(functionName, package = NULL)
whatis(functionName, package = NULL)
functionName |
function name to search for |
package |
package name containing the function. Leave unentered if this is a shorthand function |
help for the particular function
pkgname <- 'qpdf' #pacakge name shortenPkg(pkgname,TRUE) #shorten the package index(pkgname) #index the package functions shortened whatis('qpd.pl') #choose a function name and find help
pkgname <- 'qpdf' #pacakge name shortenPkg(pkgname,TRUE) #shorten the package index(pkgname) #index the package functions shortened whatis('qpd.pl') #choose a function name and find help