R Crashing While Displaying Ggplot After Update (Process Memory Read Out of Range)

R crashing while displaying ggplot after update (process memory read out of range)

This tweet from Kevin Ushey says:

PSA: If you're an RStudio user planning to upgrade to R 4.1.0, you may want to install the preview release of RStudio (https://rstudio.com/products/rstudio/download/preview/) -- otherwise, you may see RStudio crash when you try to use ggplot2.

The version number is "1.4.1714-2 Preview", so well ahead of the 1.4.1106 version you're installing via apt. Release notes on that page include

Support for the upcoming R 4.1.0 release, including the new |> pipe, (x) function shorthand, and new graphics engine.

Another alternative would be to downgrade R to an older version; for Windows the 4.0.5 binary appears to be available here. Unfortunately, the MacOS download page only appears to offer 3.6.3 in previous versions (not any 4.0.x releases) — which feels like a long way to downgrade.

R ggplot2, invalid unit error when using geom_histogram

The error arised from the fact the version of ggplot2 installed was older than the R version (I have to install the packages from a local repository, so sometimes they are not updated).
Once I installed the lastest version, it disappeared.
Thanks to everyone who investigated the issue.

Other plots disappear when DataExplorer::plot_str() called

I think the reason is a simple one: you're not outputting a real plot (static).

DataExplorer::plot_intro(mtcars) is the problematic "plot" and the underlying code for this includes diagonalNetwork towards the end of the function:

DataExplorer
function (data, type = c("diagonal", "radial"), max_level = NULL,
print_network = TRUE, ...)
{
i <- idx <- parent <- NULL
str_output_raw <- capture.output(str(data, vec.len = 0, give.attr = FALSE,
give.length = FALSE, list.len = 2000000000L))
str_output <- unlist(lapply(str_output_raw, function(x) {
gsub(" \\.{2}\\@", "\\$\\@", x)
}))
n <- length(str_output)
base_split <- tstrsplit(str_output[2:n], "\\$")
nest_level <- (nchar(base_split[[1]]) - nchar(gsub(" \\.{2}",
"", base_split[[1]])))/3 + 1
diff_nl <- diff(nest_level)
s4_start_index <- which(diff_nl > 1L) + 1L
if (length(s4_start_index) > 0) {
s4_end_index <- which(diff_nl == -2L)
s4_index_range <- unique(unlist(lapply(s4_start_index,
function(i) {
seq.int(i, s4_end_index[which.min(abs(s4_end_index -
i))])
})))
nest_level[s4_index_range] <- nest_level[s4_index_range] -
1L
}
if (is.null(max_level)) {
max_level <- max(nest_level)
}
else if (max_level <= 0 | max_level > max(nest_level)) {
stop(paste0("max_level should be between 1 and ",
max(nest_level)))
}
else {
max_level <- max_level
}
comp_split <- tstrsplit(base_split[[2]], ":")
comp_root <- gsub(" ", "", comp_split[[1]])
comp_root[which(comp_root == "")] <- make.names(comp_root[which(comp_root ==
"")], unique = TRUE)
if (anyDuplicated(comp_root))
comp_root[which(duplicated(comp_root))] <- make.names(comp_root[which(duplicated(comp_root))],
unique = TRUE)
comp_output <- paste0(comp_root, " (", trimws(gsub("NULL|\\.{3}|\\.{2}",
"", comp_split[[2]])), ")")
str_dt <- data.table(idx = seq_along(nest_level), nest_level,
parent = comp_output)[nest_level <= max_level]
str_dt <- str_dt[str_dt[, list(i = idx, nest_level = nest_level -
1, child = parent)], on = list(nest_level, idx < i),
mult = "last"]
drop_columns(str_dt[is.na(parent), `:=`(parent, paste0("root (",
str_output[1], ")"))], c("idx", "nest_level"))
str_to_list <- function(str_dt, root_name = as.character(str_dt[["parent"]][1])) {
str_list <- list(name = root_name)
children <- str_dt[parent == root_name][["child"]]
if (length(children) > 0) {
str_list[["children"]] <- lapply(children,
str_to_list, str_dt = str_dt)
}
str_list
}
str_list <- str_to_list(str_dt)
if (print_network) {
type <- match.arg(type)
if (type == "diagonal")
print(diagonalNetwork(str_list, ...))
if (type == "radial")
print(radialNetwork(str_list, ...))
}
invisible(str_list)
}

where diagonalNetwork uses htmlwidgets:

function (List, height = NULL, width = NULL, fontSize = 10, fontFamily = "serif", 
linkColour = "#ccc", nodeColour = "#fff", nodeStroke = "steelblue",
textColour = "#111", opacity = 0.9, margin = NULL)
{
if (!is.list(List))
stop("List must be a list object.")
root <- List
margin <- margin_handler(margin)
options = list(height = height, width = width, fontSize = fontSize,
fontFamily = fontFamily, linkColour = linkColour, nodeColour = nodeColour,
nodeStroke = nodeStroke, textColour = textColour, margin = margin,
opacity = opacity)
htmlwidgets::createWidget(name = "diagonalNetwork",
x = list(root = root, options = options), width = width,
height = height, htmlwidgets::sizingPolicy(padding = 10,
browser.fill = TRUE), package = "networkD3")
}

htmlwidgets is an interactive "plot" and opens under RStudio's viewer pane and not the static plots pane.



Related Topics



Leave a reply



Submit