正在工作的R脚本代码未在Markdown中工作-RStudio挂起

正在工作的R脚本代码未在Markdown中工作-RStudio挂起,r,rstudio,r-markdown,R,Rstudio,R Markdown,有人能帮助我理解有效的r脚本代码是如何导致rStudio中的标记文档挂起并变得无响应,直到我必须终止会话和IDE吗?也没有编制任何文件 背景: 在两台不同的机器上试用,运行最新的rStudio版本 Windows 7和Windows 10上的0.99.489和R 3.2.2(64位) 尝试使用packrat管理包 尝试从项目目录中加载形状文件 尝试从spdep项目下载加载其他形状文件 再次尝试重新安装程序包 R脚本 获取所需的库并加载它们 #Install the GIS packages

有人能帮助我理解有效的r脚本代码是如何导致rStudio中的标记文档挂起并变得无响应,直到我必须终止会话和IDE吗?也没有编制任何文件

背景:

  • 在两台不同的机器上试用,运行最新的rStudio版本 Windows 7和Windows 10上的0.99.489和R 3.2.2(64位)
  • 尝试使用packrat管理包
  • 尝试从项目目录中加载形状文件
  • 尝试从spdep项目下载加载其他形状文件
  • 再次尝试重新安装程序包
R脚本 获取所需的库并加载它们

#Install the GIS packages
install.packages("spdep",dependencies = TRUE)
install.packages("maptools",dependencies = TRUE)
#Load the libraries
library(spdep)
library(maptools)
这在R中起作用(您需要在系统上获得形状文件的正确位置)

#查看库文件的存储位置
.libPaths()
#使用maptools中的readShapePoly函数加载spdep包中的Eire形状文件(需要将windows中的斜杠更改为R中支持的斜杠)

eireMap这将允许您在重新安装包之前检查包(并且在加载包时不显示任何消息)。然后,它使用跨平台的方式获取所需的shapefile的文件名,然后读取并打印它。单独的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
```
---
输出:html\u文档
---
```{r echo=FALSE,message=FALSE}
如果(!require(spdep))安装.packages(“spdep”,dependencies=TRUE)
如果(!require(maptools))安装.packages(“maptools”,dependencies=TRUE)
需要(spdep)
需要(地图工具)
```
```{r}

eire_shp创建“eireMap”的代码行似乎不同,这是故意的吗?FWIW
system.file(“etc/shapes/eire.shp”,package=“spdep”)
是获取该形状文件的正确方法。还有,你为什么每次编织时都要强制重新安装包装?谢谢,你的方式更干净,但更重要的是,它可以在降价中起作用
---
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
```
---
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
```