> sarcastic("sample text")
[1] sAmPle teXT
Uhhhhhhh....
They let this guy talk?
Is that it?
"That's because I'm SUCH a thoughtful person"
↑
sarcasm
lapply
> sarcastic("sample text")
[1] sAmPle teXT
Functionals
Functions that accept a function as an argument, and return a vector as output
lapply
lapply
Function "b
"
🐝( )
=
lapply
lapply( , 🐝)
=
R: lapply
sarcastic = function(text) {
letters = strsplit(text, split = '')
lEtTeRs = lapply(letters, FUN = function(each_vec_element){
vec = lapply(each_vec_element, function(each_letter) {
return(randcase()(each_letter))
})
return(paste0(vec, collapse = ''))
})
if (length(lEtTeRs) == 1) {
return(lEtTeRs[[1]])
} else {
return(as.character(lEtTeRs))
}
}
Python: List comprehension
text_split = split_characters(text)
sarcastic_text = [''.join(
[randcase(char) for char in word]
) for word in text_split]
return(sarcastic_text)
Javascript: for loop
textTransform = function (text) {
let result = '';
for (let letter of text) {
test = Math.round(Math.random())
if (test === 1) {
letter = letter.toUpperCase()
result += letter
} else {
letter = letter.toLowerCase()
result += letter
}
}
return result
}
Error handling
# Set special error handling behavior
options(error = recover)
> recover
function () {
if (.isMethodsDispatchOn()) {
tState <- tracingState(FALSE)
on.exit(tracingState(tState))
}
calls <- sys.calls()
from <- 0L
...
}
options(show.error.messages = FALSE)
🤔
Pranks
evil.R |>
Romain Francois
# no information in error messages, just a shruggy
unlockBinding("stop", baseenv() )
assign("stop",
local({
function (..., call. = TRUE, domain = NULL) {
.Internal(stop(FALSE, "\n\t¯\\_(ツ)_/¯\n"))
}
}),
pos = baseenv()
)
Error: ¯\_(ツ)_/¯
{praise} |> Gábor Csárdi
> praise::praise("You are a ${adjective} student!")
[1] "You are a marvelous student!"
> praise::praise("${exclamation}, ${creating} this ${rpackage} must have been tough!")
[1] "hooray, making this software must have been tough!"
Demoralizing errors
Demoralizing errors
demoralizing_errors = function(silent = FALSE) {
dem_error = function() {
ridicule_proc = getOption('ridicule_probability')
if (is.null(ridicule_proc)) ridicule_proc = 0.1
err = gsub(pattern = '\\n(?!.*\\n)',
replacement = '. ',
x = geterrmessage(), perl = TRUE)
message(err, appendLF = FALSE)
message(ridicule(proc = ridicule_proc))
}
options(show.error.messages = FALSE, error = dem_error)
}
Ridicule
ridicule = function(hurt = NULL, proc = 0.1) {
n = 6
if (is.null(hurt)) {
hurt = as.character(sample(seq(0,5), size = 1, prob = c(1-proc, rep(proc/(n-1), (n-1)))))
} else {
hurt = as.character(sample(c(0,hurt), size = 1, prob = c(1-proc, proc)))
}
switch(hurt,
'0' = invisible(NULL),
'1' = praise("${adjective}, your computer remarked, in annoyance."),
'2' = sarcastic(praise("${adjective}.")),
'3' = sarcastic(praise("That was ${adjective}.")),
'4' = sarcastic(praise("${exclamation}${exclamation} that was ${adverb} ${adjective}.")),
'5' = sarcastic(praise("${exclamation} ${exclamation} ${exclamation} you're a ${adjective} coder."))
)
}
Demoralizing errors
Prank your friends
{sarcasm}
remotes::install_github("https://github.com/awong234/sarcasm")
.Rprofile
options('ridicule_probability' = 0.01)
sarcasm::demoralizing_errors(silent = TRUE)
{reticulate}
Python in an R Package
inst/
directorysystem.file(package='package_name', 'path')
to reference subdirs of the inst/
directoryreticulate::import_from_path()
along with system.file
to use your python scripts in an R sessionhttps://github.com/awong234/sarcasm-pres
https://www.alecsalces.com/presentations/sarcasm_pres
Additional thanks to:
|>
reveal.js