rstudio (1.4.1717) 抱怨源不可用

时间:2021-07-20 20:16:55

标签: r ggplot2 rstudio

1。总结:

注意:我只是将 ggplot2 用作可公开访问的工作示例。我的实际代码不是基于 tidy-verse 包。

在下面的例子中,我编辑了 ggplot2::geom_point 并尝试调试它,这仍然触发臭名昭著的“源不可用通知”

2.环境:

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   

3.设置 keep.source.pkgs 并下载 ggplot2

R.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)  

4.在 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, ...))
}

5.做一个简单的情节,这应该可以毫无怨言地开源:

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")


6.仍然抱怨:

又是那个黄色三角形......

enter image description here

0 个答案:

没有答案