有人可以帮助我了解有效的r脚本代码如何导致rStudio中的markdown文档挂起并对我必须终止会话和IDE的点无响应?没有文件编织
背景
R脚本 获取所需的库并加载它们
#Install the GIS packages
install.packages("spdep",dependencies = TRUE)
install.packages("maptools",dependencies = TRUE)
#Load the libraries
library(spdep)
library(maptools)
这适用于R(您需要获得系统中形状文件的正确位置)
#See where the library files are stored
.libPaths()
#Load the Eire shape file which came in spdep package using the readShapePoly function from maptools (needed to change the slashes from windows to those supported in R)
eireMap <- readShapePoly("C:R/3.2/spdep/etc/shapes/eire.shp"[1],ID="names", proj4string=CRS("+proj=utm +zone=30 +units=km"))
#Plot the map as there was no problem reading the shape file correctly in R script
plot(eireMap)
R Markdown
---
title: "GIS using R"
author: "Me"
date: "18 November 2015"
output: word_document
---
This is an R Markdown document of the R worksheet for GIS. Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code contained in that snippet
```{r, echo=FALSE}
#Install the packages if not done already
install.packages("spdep",dependencies = TRUE)
install.packages("maptools",dependencies = TRUE)
```
Load the libraries
```{r, echo=FALSE}
library(spdep)
library(maptools)
```
See where the library files are stored
```{r}
.libPaths()
```
Try to Load the Eire shape file but it causes R Studio to hang and become unresponsive
```{r}
eireMap <- readShapePoly("C:R/win- library/3.2/spdep/etc/shapes/eire.shp"[1],ID="names", proj4string=CRS("+proj=utm +zone=30 +units=km"))
```
Can't plot the map because the system has hung by this stage
```{r}
plot(eireMap)
names(eireMap)
eireMap $names
```
答案 0 :(得分:0)
这将允许您在重新安装之前检查包(并且在加载时不显示任何消息)。然后它使用跨平台的方式获取所需的shapefile的文件名,然后读取&amp;绘制它。各个R代码行(即非Rmd)在R控制台和RStudio中工作正常+ Rmd在我的OS X系统和Linux系统上编织得很好。有更优雅的方法来执行包检查/加载,但这可以让您快速检查系统中是否存在更大的问题。
---
output: html_document
---
```{r echo=FALSE, message=FALSE}
if (!require(spdep)) install.packages("spdep",dependencies=TRUE)
if (!require(maptools)) install.packages("maptools",dependencies=TRUE)
require(spdep)
require(maptools)
```
```{r}
eire_shp <- system.file("etc/shapes/eire.shp", package="spdep")
eireMap <- readShapePoly(eire_shp, ID="names",
proj4string=CRS("+proj=utm +zone=30 +units=km"))
```
```{r}
plot(eireMap)
names(eireMap)
eireMap$names
```