Nothing
addin_warning <- function(w) {
msg <- c(x = w$message)
inform(msg)
invokeRestart("muffleWarning")
}
addin_run <- function(ctx, apply_fn) {
sel <- ctx$selection[[1]]
text <- sel$text
if(!nchar(text)) {
# error and warning don't work quite the way I want
msg <- c(x = "No text selected; please select the code to process.")
inform(msg);
return(invisible(NULL))
}
lines <- strsplit(text, "\n", fixed = TRUE)[[1]]
result <- apply_fn(lines)
# Don't eat blank line at end of selection
if(endsWith(text, "\n")) result <- paste0(result, "\n")
rstudioapi::insertText(location = sel$range, text = result, id = ctx$id)
invisible(NULL)
}
# Convert NM addin -------------------------------------------------
addin_apply_convert_nm <- function(lines) {
if(has_block_markers(lines)) {
result <- modelsplit(lines)
result <- convert_fort_if_spec(result)
result <- convert_semicolons_spec(result)
result <- modelunsplit(result)
} else {
result <- convert_fort_if(lines)
result <- convert_semicolons(result)
}
paste(result, collapse = "\n")
}
addin_convert_nm <- function() {
ctx <- rstudioapi::getActiveDocumentContext()
addin_run(ctx, addin_apply_convert_nm)
}
# Add semicolons addin ---------------------------------------------
addin_apply_semicolons <- function(lines) {
if(has_block_markers(lines)) {
result <- modelsplit(lines)
result <- convert_semicolons_spec(result)
result <- modelunsplit(result)
} else {
result <- convert_semicolons(lines)
}
paste(result, collapse = "\n")
}
addin_add_semicolons <- function() {
ctx <- rstudioapi::getActiveDocumentContext()
addin_run(ctx, addin_apply_semicolons)
}
# Convert pow addin ---------------------------------------------
addin_apply_convert_pow <- function(lines) {
if(has_block_markers(lines)) {
result <- modelsplit(lines)
withCallingHandlers({
result <- convert_pow_spec(result)
}, warning = addin_warning)
result <- modelunsplit(result)
} else {
withCallingHandlers({
result <- convert_pow(lines)
}, warning = addin_warning)
}
paste(result, collapse = "\n")
}
addin_convert_pow <- function() {
ctx <- rstudioapi::getActiveDocumentContext()
addin_run(ctx, addin_apply_convert_pow)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.