注意:我只是将 ggplot2 用作可公开访问的工作示例。我的实际代码不是基于 tidy-verse 包。
在下面的例子中,我编辑了 ggplot2::geom_point
并尝试调试它,这仍然触发臭名昭著的“源不可用通知”
R.version
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 1.0
year 2021
month 05
day 18
svn rev 80317
language R
version.string R version 4.1.0 (2021-05-18)
nickname Camp Pontanezen
keep.source.pkgs
并下载 ggplot2R.utils::setOption("keep.source.pkgs",TRUE) # this does nothing but others have suggested it
temp = tempfile()
download.file("https://cran.r-project.org/src/contrib/ggplot2_3.3.5.tar.gz",temp)
install.packages(temp, repos = NULL, type = "source")
unlink(temp)
browser()
ggplot2::geom_point
我运行 trace(geom_point, edit = T)
并编辑文件,请注意第 4 行:
function (mapping = NULL, data = NULL, stat = "identity", position = "identity",
..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
{
browser() # test local source-availability
layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...))
}
theme_set(theme_bw()) # pre-set the bw theme.
data("midwest", package = "ggplot2")
# make a scatterplot
gg <- ggplot(midwest, aes(x=area, y=poptotal)) +
geom_point(aes(col=state, size=popdensity)) +
geom_smooth(method="loess", se=F) +
xlim(c(0, 0.1)) +
ylim(c(0, 500000)) +
labs(subtitle="Area Vs Population",
y="Population",
x="Area",
title="Scatterplot",
caption = "Source: midwest")
又是那个黄色三角形......