安装 Rcartogram 包 - 错误消息 [英] installing Rcartogram packages - error message

查看:19
本文介绍了安装 Rcartogram 包 - 错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个类似于此处

的地图

从链接安装不起作用:

`install.packages('Rcartogram', repos = 'http://www.omegahat.org/R', type = 'source')`安装包到‘C:/Users/Milena/Documents/R/win-library/3.2’(因为 `lib` 未指定)install.packages 中的警告:包Rcartogram"不可用(适用于 R 版本 3.2.0)

都不是来自 zip 文件:

<块引用>

install.packages("C:/Users/Milena/Downloads/Rcartogram_0.2-2.tar.gz",repos = NULL, type = "source")

安装包到‘C:/Users/Milena/Documents/R/win-library/3.2’(因为 lib 未指定)* 安装 sourceRcartogram ...****************************************************
警告:这包有一个配置脚本它可能需要手动配置*****************************************************

** 库

*** arch - i386 警告:运行命令 'make -f "Makevars" -f "C:/PROGRA~1/R/R-3.2.0/etc/i386/Makeconf" -f"C:/PROGRA~1/R/R-3.2.0/share/make/winshlib.mk" SHLIB="Rcartogram.dll"OBJECTS="Rcart.o car.o"' 状态为 127 错误:编译失败'Rcartogram' 包* 删除 install.packages 中的C:/Users/Milena/Documents/R/win-library/3.2/Rcartogram"警告:运行命令'"C:/PROGRA~1/R/R-3.2.0/bin/x64/R" CMD 安装 -l"C:\Users\Milena\Documents\R\win-library\3.2""C:/Users/Milena/Downloads/Rcartogram_0.2-2.tar.gz"' 的状态为 1install.packages 中的警告:安装包C:/Users/Milena/Downloads/Rcartogram_0.2-2.tar.gz"有非零退出状态

我该如何解决这个问题?

我在 Windows 机器上工作.

感谢所有花时间查找此问题的人.

这是我的sessionInfo:

R 版本 3.2.0 (2015-04-16)平台:x86_64-w64-mingw32/x64(64位)运行环境:Windows 8 x64 (build 9200)语言环境:[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C[5] LC_TIME=English_United Kingdom.1252附带的基础包:[1] stats graphics grDevices utils datasets 方法基础其他附加包:[1] fftw_1.0-3通过命名空间加载(而不是附加):[1] 工具_3.2.0

解决方案

在 Windows 上安装 Rcartogram

Rcartogram 是一个 R 包(由 Duncan Temple Lang 开发),其主要目的是为一些 C 代码(由 Mark Newman 编写)提供一个 R 包装器,该代码实际上完成了构建地图(又名变形地图)的工作.Mark Newman 编写的 C 代码使用了 FFTW(西方最快的傅立叶变换)编译库.

您问题中的链接 Truc Viet Le 描述了如何在 Unix 系统上安装 Rcartogram.将 Rcartogram 安装到 Windows 系统上需要一些额外的技巧和陷阱,尽管从本质上讲,这几乎是相同的过程.

要在 Windows 系统上安装 Rcartogram,您首先需要安装所有先决条件,即:

  • Rtools 程序套件(您需要能够将任何涉及 C 代码的 R 包安装到 Windows 机器上),以及
  • FFTW 库(Rcartogram 代码使用该库).

然后,当您第一次安装 Rcartogram 时,您需要告诉 R 在哪里可以找到 FFTW 库,并且几乎可以肯定,每当您加载 Rcartogram 时,您几乎肯定需要让 R 知道在哪里可以找到 FFTW 库,例如通过 library(Rcartogram) 在 R 会话中.

我发现我还需要对 Rcartogram R 代码进行一些非常小的更改(主要是为了使其与编写以来对 R 语法的更改保持一致),以便顺利安装并正确运行窗户.

所以完整的答案包括几个步骤.

第一步:安装Rtools套件

我怀疑您需要安装 Rtools 才能克服状态 127 错误.关于如何做到这一点的官方说明在这里 http://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset.有关于如何将 Rtools 安装到网络上其他地方的 Windows 系统的用户友好解释——参见例如 https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows.(官方说明还告诉您如何安装许多其他东西,如果您想在 Windows 上从源代码构建 R 本身,或者使用 LaTeX 生成包文档,则需要这些东西,但您不需要所有这些东西来获取 Rcartogram工作).

有点长的答案:我现在可以复制您的 status 127 错误 ---通过从我的 PATH 中删除对 Rtools 所在目录的引用.当我这样做时,Windows cmd shell(您可能会在其中键入 R CMD INSTALL ... 找不到 Rtools 可执行文件并导致 127 错误消息.同样尝试运行 install.packagesR 中的 () 也以同样的方式失败,因为在引擎盖下 install.packages 调用 Windows cmd shell.

为什么需要 Rtools?Well Rcartogram 是一个包含 C 代码和纯 R 代码的包.事实上,它主要是 C 代码——来自 Mark Newman.从源代码安装包含 C 代码的包需要 C 编译器.事实上,最好(几乎是必要的)它是构建 R 本身的同一个 C 编译器.这就是 Rtools 的主要功能——可安装在 Windows 版本的 C 编译器上.在 Windows 中运行 C 编译器还需要一些额外的 shell 命令(也就是小程序),这就是 Rtools 的其余部分.大多数(开源)C 社区似乎都在 Unix(或其变体)世界中工作,而那些额外的命令(实际上是 C 编译器本身)是 Unix 中标准"系统的一部分.只有我们这些在 Windows 中工作的人需要安装 Rtools,它是从 Unix 到 Windows 的必要工具的端口.

第 2 步:安装 FFTW 库

最初我从这里获得 FFTW 库 http://www.fftw.org/ .

有两个版本,一个 32 位版本和一个 64 位版本.在 Windows 64 位机器上,您需要两个版本.(另外,可能有一种方法可以通过在安装 Rcartogram 时设置标志来逃脱,但我自己还没有测试过该路线).32位版本解压到子目录/i386,64位版本解压到子目录/x64.就我而言(见下文),我将它们作为C:/msys/fftwtest"的子目录.(除了这些子目录是 R 使用的约定 - 您理论上可以将它们放在其他地方,但为什么要增加额外的复杂性!).

困扰我很长一段时间的一个陷阱是这些库是动态库(即 .dll s),因此 - 后来 - 我需要确保在我的电脑上安装它们时,我将它们放在在我的 PATH 上(或者我通过添加位置 - 也就是目录 - 它们的安装位置)来更改我的 PATH 否则我在 R 完成安装包之前所做的最终检查中得到非常无用的错误消息.PATH 中应包含 32 位和 64 位(子)目录.

第 3 步:告诉 R 在哪里可以找到 FFTW 库

在尝试安装 Rcartogram 时告诉 R(在 Windows 机器上)在哪里可以找到 FFTW 库的技巧是将 src/Makevars.win 文件添加到Rcartogram 包.这意味着您必须先解压缩 Rcartogram tar.gz 文件,然后才能进行此更改.(另外:我使用 7zip 在我的机器上解压缩这些类型的文件).

我的 src/Makevars.win 文件(它是一个文本文件)有 2 行,

PKG_CPPFLAGS=-I"C:\msys\fftwtest\x64\include" -DNOPROGRESSPKG_LIBS=-L"C:\msys\fftwtest\x64\lib" -L"C:\msys\fftwtest\i386\lib" -lfftw3 -lm

引号中的文件名是我放置 FFTW 库版本的地方.(这些并不是我下载的那些,一路上我学会了如何从源代码编译 FFTW,并制作了我自己的副本,但解释如何做到这一点是一个很长的故事,所以我不会在这里尝试.)/p>

PKG_CPPFLAGS 行中提到的目录是包含 C 预处理器需要的名为 fftw3.h 的头文件的目录.指向 32 位(\i386 子目录)还是 64 位(\x64 子目录)都没有关系 - fftw3.h 文件是 C 源文件,无论 R 为什么架构安装都是相同的.

PKG_LIBS 行中提到的 2 个目录是可以找到名为 libfftw3.something 的文件的目录,链接器在编译步骤结束时将所有内容放在一起时需要这些目录.something 可能是.dll"(在这种情况下,子目录可能是 \bin 而不是 \lib),也可能是.a"或.la"(这是 R 寻找的当它使用我在学习如何从源代码编译 FFTW 后创建的静态 FFTW 库时).

需要 2 个目录,因为 R 默认情况下会尝试在 Windows 机器上安装 32 位和 64 位版本的 Rcartogram.如果您提供 .dll 格式的 FFTW 库文件,那么这些库文件必须在您的 PATH 中(因为当您尝试执行 library(Rcartogram) R 需要在加载已安装的文件时再次找到 FFTW dll 库)Rcartogram 包)(另外,这就是为什么最后我编译了我自己的静态 FFTW 库,所以我不必在 Windows 环境中弄乱我的 PATH 变量).

如果您使用从以上链接下载的二进制文件,fftw3.h 和 libfftw3.dll 文件都在同一(子)目录中,libfftw3.dll 文件实际上称为 libfftw3-3.dll,因此在这种情况下,您的 src/Makevars.win 文件需要是:

PKG_CPPFLAGS=-I"main libfftw directory\x64" -DNOPROGRESSPKG_LIBS=-L"主libfftw目录\x64" -L"主libfftw目录\i386" -lfftw3-3 -lm

与我的 src/Makevars.win 的主要区别是:

  • 插入您的主libfftw目录的名称 - 即您创建/i386/x64子目录时的父目录解压下载的 FFTW 二进制文件
  • 删除\include\lib 子目录,以及
  • -libfftw3 改为-libfftw3-3(还要注意必须在每个-(减号)在 -L-l 标志的开头签名.

Makevars.win 文件在做什么?它告诉 R 安装进程在尝试预处理、编译和链接 Rcartogram 的 src 子目录中的 C 代码时需要的 标志.PKG_CPPFLAGS 的值是 C 预处理器的一组标志,PKG_LIBS 的值是链接步骤的一组标志.

  • -I 是一个标志,表示当 C 预处理器正在查找包含文件时,尝试在以下目录中查找",因此在上面的示例中,它表示查找 主 libfftw 目录\x64".它寻找的包含文件是 fftw3.h(该文件名被埋在 Rcartogram 内的 C 代码中)
  • -L 标志表示当链接器从您希望使用的任何库中查找文件时,请尝试在以下目录中查找",因此 -L"main libfftw 目录\x64" 表示尝试查看 "main libfftw directory\x64" 目录.您可以(并且需要)在该搜索路径上拥有 1 个以上的目录 - 链接器一直在寻找,直到找到它正在寻找的内容(或者找不到要查找的位置并给出错误消息),并且
  • -l 标志给出了链接器应查找的库文件的名称,但不是逐字逐字的 --- 相反,该名称是根据您在 a 之后输入的内容构建的(对我来说有点疯狂) 来自 unix 世界的约定.因为库的文件名总是以lib"开头,所以约定的第一部分是将lib"放在标记中的名称之外.库的文件名可以有几个不同的扩展名(例如.dll"或.a"),因此约定的第二部分是您将文件扩展名保留在 -l 标志值也是如此,让链接器整理出它想要的东西.所以 –lfftw3 说寻找一个名为 libfftw3.dll 或一个名为 libfftw3.a 的文件(可能还有其他可能的扩展名,我不知道).

下载的dll实际上叫做libfftw3-3.dll,(不像我自己编译的,叫做libfftw3.a)因此需要改变–l 标记为 –lfftw3-3

NB 如果您使用的是下载的 FFTW 库,它使用 .dlls,请确保您已将它们放在您的 PATH 中(请参阅第 2 步的最后一段)嗯.

第 4 步:对 Rcartogram C 代码的小修正

我发现我必须对 Rcartogram 代码本身进行另外两个小的更改才能使事情运行.

首先在文件 R/cart.R 中有两行,都使用了 .Call( ) 函数.我需要在 .Call 函数中再添加一个参数(即 PACKAGE = "Rcartogram"),例如

tmp = .Call("R_makecartogram", popEls, x, y, dim, as.numeric(blur))

变成了

tmp = .Call("R_makecartogram", popEls, x, y, dim, as.numeric(blur), PACKAGE = "Rcartogram")

同样,在cart.R下方,更改后的.Call变成了

.Call("R_predict", object, as.numeric(x), as.numeric(y), ans, dim(object$x), PACKAGE = "Rcartogram")

第二,再次在 R/cart.R 中,我不得不改变

tmp = rep(as.numeric(NA), length(x))ans = 列表(x = tmp,y = tmp)

# 避免同一个向量(tmp)由于 R 的原因被发送到 C 两次的问题# 修改时复制规则tmp_x = rep(as.numeric(NA), 长度(x))tmp_y = rep(as.numeric(NA), length(y))ans = 列表(x = tmp_x,y = tmp_y)

我花了很多功夫才找到这个,但没有它,Rcartogram 的演示给出了错误的结果(即使它运行正常).

第 5 步:实际安装 Rcartogram

您现在应该可以安装 Rcartogram.要么

  • 通过打开一个 cmd 窗口,将目录(cd 更改为)解压和修改后的 Rcartogram 包源代码所在的位置,然后键入 R CMD INSTALL --preclean .

  • 通过启动 R 会话,将工作目录设置为 Rcartogram 源所在的位置并键入 install.packages(".", repos = NULL, type = 'source', INSTALL_opts = "--preclean")

. 之所以有效,是因为您已将 cd 转到 Rcartogram 源代码所在的目录.--preclean 标志告诉 R 在开始之前整理 Rcartogram 中 C 代码的早期(失败)尝试中的任何剩余中间文件.如果你走到这一步并且仍然遇到问题,也可以添加一个 --debug 标志.它提供了有关安装失败原因的更多详细信息.

第 6 步:享受变形地图

我自己才刚刚开始实际使用 Rcartogram(我花了一段时间才走到这一步!),但您可能想查看 getcartr --- R 包.那个包使用了 Rcartogram,看起来很整洁!并且 github 网站上给出的安装说明对我来说是第一次(虽然我已经安装了 devtools 并且可以使用).

希望这会有所帮助(并祝贺所有读到这里的人)

2017 年 5 月更新

我已经有几年没有研究这个了(所以不能保证它仍然有效),但是在我写完上面的帖子之后,我在 https://github.com/Geoff99/Rcartogram/tree/WindowsInstall.

查看包含

的 WindowsInstall 分支

(要使用本教程,您需要使用分叉存储库的 WindowsInstall 分支!)

I am trying to build a cartogram like here

Installation from the link does not work:

`install.packages('Rcartogram', repos = 'http://www.omegahat.org/R', type = 'source')`
Installing package into ‘C:/Users/Milena/Documents/R/win-library/3.2’
(as `lib` is unspecified)

Warning in install.packages :
  package ‘Rcartogram’ is not available (for R version 3.2.0)

Neither from the zip file:

install.packages("C:/Users/Milena/Downloads/Rcartogram_0.2-2.tar.gz", repos = NULL, type = "source")

Installing package into ‘C:/Users/Milena/Documents/R/win-library/3.2’ (as lib is unspecified) * installing source package Rcartogram ... **********************************************
WARNING: this package has a configure script It probably needs manual configuration **********************************************

** libs

*** arch - i386 Warning: running command 'make -f "Makevars" -f "C:/PROGRA~1/R/R-3.2.0/etc/i386/Makeconf" -f "C:/PROGRA~1/R/R-3.2.0/share/make/winshlib.mk" SHLIB="Rcartogram.dll" OBJECTS="Rcart.o cart.o"' had status 127 ERROR: compilation failed for package 'Rcartogram' * removing 'C:/Users/Milena/Documents/R/win-library/3.2/Rcartogram' Warning in install.packages : running command '"C:/PROGRA~1/R/R-3.2.0/bin/x64/R" CMD INSTALL -l "C:\Users\Milena\Documents\R\win-library\3.2" "C:/Users/Milena/Downloads/Rcartogram_0.2-2.tar.gz"' had status 1 Warning in install.packages : installation of package ‘C:/Users/Milena/Downloads/Rcartogram_0.2-2.tar.gz’ had non-zero exit status

How can I solve this problem?

I am working on Windows machine.

Thank you to everyone who took the time to look up this question.

Here is my sessionInfo:

R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fftw_1.0-3

loaded via a namespace (and not attached):
[1] tools_3.2.0

解决方案

Installing Rcartogram on Windows

Rcartogram is an R package (by Duncan Temple Lang) whose main purpose is to provide a R wrapper for a some C code (written by Mark Newman) which actually does the work of constructing a cartogram (aka morphing a map). The C code written by Mark Newman makes use of the FFTW (fastest Fourier Transform in the West) compiled library.

The link in your question by Truc Viet Le describes how to install Rcartogram on a Unix system. There are a few extra tricks and traps involved in getting Rcartogram onto a Windows system, even though at its heart, it is pretty much the same process.

To install Rcartogram on a Windows system you need first to install all the pre-requisites, namely:

  • the Rtools suite of programs (which you need to be able to install any R package which involves C code onto a Windows machine), and
  • The FFTW library (which the Rcartogram code uses).

You then need to tell R where to find the FFTW library when you are first installing Rcartogram, and you will almost certainly need to let R know where to find the FFTW library whenever you load Rcartogram, eg via library(Rcartogram) in an R session.

I found I also needed to make a few very small changes to the Rcartogram R code (mostly to bring it into line with changes to R syntax since it was written) in order to get it to install happily, and run correctly on Windows.

So the full answer involves several steps.

Step 1 : Install the Rtools suite

I suspect you need to install Rtools in order to get past the status 127 error. The official instructions on how to do that are here http://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset. There are user friendly explanations of how to install Rtools into a Windows system elsewhere on the web --- see for example https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows . (The official instructions tell you how to install lots of other stuff as well, that you need if you want to build R itself from source on Windows, or produce package documentation using LaTeX, but you don't need all that stuff to get Rcartogram working).

A bit longer answer: I can now replicate your status 127 error ---by removing the references to directories where Rtools lives from my PATH. When I do that the Windows cmd shell (where you might type R CMD INSTALL … can’t find the Rtools executables and that results in the 127 error message. Likewise trying to run install.packages() from within R also fails the same way, since under the hood install.packages calls the Windows cmd shell.

Why do you need Rtools? Well Rcartogram is a package which includes C code, as well as pure R code. In fact it is mostly C code – from Mark Newman. Installing from source for a package which includes C code requires a C compiler. In fact it is best (almost essential) that it is the same C compiler that R itself was built from. That is what Rtools mostly is – an installable on Windows version of a C compiler. Running a C compiler in Windows needs a few extra shell commands (aka small programs) as well and that is what the rest of Rtools is. Most of the (open source) C community seem to work in a Unix (or variant thereof) world and those extra commands (and indeed the C compiler itself) are part of the "standard" system in Unix. It’s only those of us who work in Windows who need to install Rtools, which is a port of the necessary tools from Unix to Windows.

Step 2 : Install the FFTW library

Initially I got the FFTW library from here http://www.fftw.org/ .

There are two versions, a 32 bit version and a 64 bit version. On a Windows 64 bit machine you need both versions. (Aside, well there may be a way you can get away with only one, by setting flags when you install Rcartogram, but I haven't tested that route myself yet). Unzip the 32 bit version into a sub-directory /i386, and the 64 bit version into a subdirectory /x64. In my case (see below), I made these as subdirectories of "C:/msys/fftwtest". (Aside these subdirectories are conventions that R uses - you could theoretically put them elsewhere, but why make extra complications!).

One trap that stumped me for quite a while was that these libraries are dynamic libraries (ie .dll s) and so - later on - I needed to make sure that when I installed them on my pc I put them in locations that were on my PATH (or alternatively I altered my PATH by adding in the locations - aka directories - where they were installed) since otherwise I got very unhelpful error messages in the final checks that R does before it finishes installing a package. Both the 32 bit and 64 bit (sub) directories should be included in your PATH.

Step 3 : Tell R where to find the FFTW library

The trick to telling R (on a Windows machine) where to find the FFTW libraries when it is trying to install Rcartogram is to add a src/Makevars.win file into the src subdirectory of the Rcartogram package. That means you will have to unzip and untar the Rcartogram tar.gz file before you can make this change. (Aside : I use 7zip to uncompress these types of files on my machine).

My src/Makevars.win file (it is a text file) has 2 lines,

PKG_CPPFLAGS=-I"C:\msys\fftwtest\x64\include"   -DNOPROGRESS 
PKG_LIBS=-L"C:\msys\fftwtest\x64\lib" -L"C:\msys\fftwtest\i386\lib" -lfftw3 -lm

The file names in quotes are where I put my versions of the FFTW library. (These aren't exactly the ones I downloaded, along the way I learnt how to compile FFTW from source, and made my own copies, but explaining how to do that is a looong story so I won't attempt it here).

The directory mentioned in PKG_CPPFLAGS line is the one containing a header file called fftw3.h that the C pre-processor needs. It doesn't matter whether you point at the 32 bit (\i386 subdirectory) or the 64 bit (\x64 subdirectory) - the fftw3.h file is a C source file and is the same no matter what architecture R is installing for.

The 2 directories mentioned in PKG_LIBS line are the ones where files called libfftw3.something can be found, and that the linker needs when it is putting everything together at the end of the compilation step. something might be ".dll" (in which case the subdirectory might be \bin instead of \lib), or it might be ".a" or ".la" (which is what R looks for when it uses the static FFTW libraries which I created once I had learnt how to compile FFTW from source).

2 directories are needed because R by default tries to install both 32 bit and 64 bit versions of Rcartogram on Windows machines. If you supply FFTW library files in .dll format, then these are the exact same libraries that must be on your PATH (because when you try to do library(Rcartogram) R needs to find the FFTW dll libraries again while it is loading the installed Rcartogram package) (Aside, that's why in the end I compiled my own static FFTW libraries, so I didn't have to mess with my PATH variable in the Windows environment).

If you are using the downloaded binaries from the link above, the fftw3.h and the libfftw3.dll files are all in the same (sub) directory, and the libfftw3.dll file is actually called libfftw3-3.dll, so in this case your src/Makevars.win file would need to be :

PKG_CPPFLAGS=-I"main libfftw directory\x64"   -DNOPROGRESS 
PKG_LIBS=-L"main libfftw directory\x64" -L"main libfftw directory\i386"  -lfftw3-3 -lm

The key differences from my src/Makevars.win are :

  • inserting the name of your main libfftw directory - ie the parent directory under which you created the /i386 and /x64 subdirectories when you unzipped the downloaded FFTW binaries
  • the deletion of the \include and \lib sub-sub-directories, and
  • changing -libfftw3 to -libfftw3-3 (note also that there must be a space in front of each - (minus) sign at the start of the -L and -l flags).

What is the Makevars.win file doing? It is telling the R install process the flags that it will need when it tries to preprocess, compile and link the C code in Rcartogram's src subdirectory. The value of PKG_CPPFLAGS is a set of flags for the C pre-processor, and the value of PKG_LIBS is a set of flags for the link step.

  • The -I is a flag that says 'try looking in the following directory when the C pre-processor is looking for include files', so in the example above it says to look in "main libfftw directory\x64". The include file it seeks is fftw3.h (that filename is buried in the C code inside Rcartogram)
  • The -L flag says 'try looking in the following directory when the linker is looking for files from any library that you expect to use', so -L"main libfftw directory\x64" says try looking in the "main libfftw directory\x64" directory. You can (and need to) have more than 1 directory on that search path - the linker just keeps looking till it finds what it is looking for (or runs out of places to look and gives an error message), and
  • The -l flags gives the name of the library file that the linker should look for, but not verbatim --- instead the name is constructed from what you enter following a (slightly crazy to me) convention from the unix world. Because the file name of the library always begins with "lib", the first part of the convention is that you leave "lib" out of the name you put in the flag. The file name of the library can have several different extensions ( eg ".dll" or ".a") so the second part of the convention is that you leave you leave the file extension out of the -l flag value as well, and let the linker sort out what it wants. So –lfftw3 says look for a file called either libfftw3.dll or one called libfftw3.a (there may be other possible extensions as well, I'm not sure).

The downloaded dlls are actually called libfftw3-3.dll, (unlike the ones I compiled myself, which are called libfftw3.a) hence the need to change the –l flag to –lfftw3-3

NB If you are using the downloaded FFTW library which uses .dlls make sure you have put them on your PATH (see the last para of step 2) as well.

Step 4 : Small fixes to the Rcartogram C code

There were two other small changes I found I had to make to the Rcartogram code itself get things running.

First in the file R/cart.R there are two lines, both of which use the .Call( ) function. I needed to add one more argument (namely PACKAGE = "Rcartogram") to the .Call function, so for example

tmp = .Call("R_makecartogram", popEls, x, y, dim, as.numeric(blur))

became

tmp = .Call("R_makecartogram", popEls, x, y, dim, as.numeric(blur), PACKAGE = "Rcartogram")

Likewise, further down cart.R the altered .Call became

.Call("R_predict", object, as.numeric(x),  as.numeric(y), ans, dim(object$x), PACKAGE = "Rcartogram")

Second, again in R/cart.R, I had to change

tmp = rep(as.numeric(NA), length(x))
ans = list(x = tmp, y = tmp)

to

# Avoid problems with the same vector (tmp) being sent to C twice due to R's
# copy-on-modify rules
tmp_x = rep(as.numeric(NA), length(x))
tmp_y = rep(as.numeric(NA), length(y))
ans = list(x = tmp_x, y = tmp_y)

This one took me a lot of work to find, but without it, the demo for Rcartogram gave the wrong results (even though it ran OK).

Step 5 : Actually install Rcartogram

You should now be able to install Rcartogram. Either

  • by opening a cmd window, changing directory (cd to) the location where the unzipped and modified Rcartogram package source code lives, and typing R CMD INSTALL --preclean . or

  • by starting an R session, setting the working directory to wherever the Rcartogram source is and typing install.packages(".", repos = NULL, type = 'source', INSTALL_opts = "--preclean")

The . works because you have cded to directory where the Rcartogram source code lives. The --preclean flag tells R to tidy up any leftover intermediate files from earlier (failed) attempts to compile the C code in Rcartogram before it begins. If you get this far and are still having trouble, there is also a --debug flag that can be added as well. It gives more detail about why the install is failing.

Step 6 : Enjoy morphing maps

I am just getting started actually using Rcartogram myself (it took me a while to get this far!), but you may want to check out the getcartr --- R package. That package uses Rcartogram, and it seems pretty neat! And the installation instructions given on the github website worked first time for me (I do already have devtools installed and working though).

Hope this helps (and congratulations to anyone who has read this far)

Update May 2017

I haven't worked on this for a couple of years now (so no guarantees it will still work), but after I wrote the post above, I created a forked copy of RCartogram at https://github.com/Geoff99/Rcartogram/tree/WindowsInstall.

See the WindowsInstall branch which includes

(To use the tutorial, you need to use the WindowsInstall branch of the forked repository!)

这篇关于安装 Rcartogram 包 - 错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆