Dear R experts, I am new to the list and R software. I need to convert arcview file to Winbugs having R has middle package. Got from friends that it is possible following the steps: 1. Converting arcview shapefile to "cgm clear text file" 2. Downloading "convert.r" to into R 2.1 use source("convert.r") 2.2 convert("filename_cgm") without the extension. But that doesn't work, given the following errors: ---------------------------- R : Copyright 2003, The R Development Core Team Version 1.8.0 (2003-10-08) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored]> source("convert.r") > convert("transf")Error in file(file, "r") : unable to open connection In addition: Warning message: cannot open file `transf.cgm'>----------------------------------- Have i done some mistakes?Or i am missing some files? Please assist. Rgs, Orlando. [[alternative HTML version deleted]]
On Wed, 22 Oct 2003, Orlando Zacarias wrote:> Dear R experts, > I am new to the list and R software. I need to convert arcview file to Winbugs having R has middle package. Got from friends that it is possible following the steps: > 1. Converting arcview shapefile to "cgm clear text file" > 2. Downloading "convert.r" to into R > 2.1 use source("convert.r") > 2.2 convert("filename_cgm") without the extension. > But that doesn't work, given the following errors: > ---------------------------- > R : Copyright 2003, The R Development Core Team > Version 1.8.0 (2003-10-08) > R is free software and comes with ABSOLUTELY NO WARRANTY. > You are welcome to redistribute it under certain conditions. > Type 'license()' or 'licence()' for distribution details. > R is a collaborative project with many contributors. > Type 'contributors()' for more information. > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for a HTML browser interface to help. > Type 'q()' to quit R. > [Previously saved workspace restored] > > source("convert.r") > > convert("transf") > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file `transf.cgm' > > > -----------------------------------This is quite a "narrow" question based on other people knowing that you are refering to: http://www.biostat.umn.edu/~yuecui/ and the file you have downloaded from there. The most typical cause of files not being found is when you are not in the correct working directory. Use:> getwd()to access the directory name, and> list.files()to see if the name of your *.cgm file is returned. The key comment in the web page you must have used is: "Open Splus or R under the folder in which convert.s is saved" but even if you start in another folder, you can change the R working directory using> setwd("where_I_want_to_be")or from the File menu.> Have i done some mistakes?Or i am missing some files? > Please assist. > Rgs, > Orlando. > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: Roger.Bivand at nhh.no
Your question is not really clear because: - I don't know what 'convert.r' do - I don't know where 'transf.cgm' is (BTW, 'cgm' is not the usual extension for shapefiles which is 'shp'). Check if it is really in your current directory. but, yes, if what you want is to import shapefiles in R, it's easy. Look at the 'maptools' package on CRAN (there is also a 'shapefiles' package). And if you want to build an adjacency matrix for a map of polygons (as I guess from the header of you mail), look at the 'spdep' package, too. It is then possible to write a text file with your data as a list readable by WinBUGS. (I send a copy of my answer to the the R-SIG-GEO mailing list which can be of interest to you). Hope it helps. Christophe -- Christophe DECLERCQ, MD Observatoire R?gional de la Sant? Nord-Pas-de-Calais 13, rue Faidherbe 59046 LILLE Cedex FRANCE Phone +33 3 20 15 49 24 Fax +33 3 20 55 92 30 E-mail c.declercq at orsnpdc.org> -----Message d'origine----- > De : r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]De la part de Orlando Zacarias > Envoy? : mercredi 22 octobre 2003 11:58 > ? : r-help at stat.math.ethz.ch > Objet : [R] adjacency matrix > > > Dear R experts, > I am new to the list and R software. I need to convert arcview > file to Winbugs having R has middle package. Got from friends > that it is possible following the steps: > 1. Converting arcview shapefile to "cgm clear text file" > 2. Downloading "convert.r" to into R > 2.1 use source("convert.r") > 2.2 convert("filename_cgm") without the extension. > But that doesn't work, given the following errors: > ---------------------------- > R : Copyright 2003, The R Development Core Team > Version 1.8.0 (2003-10-08) > R is free software and comes with ABSOLUTELY NO WARRANTY. > You are welcome to redistribute it under certain conditions. > Type 'license()' or 'licence()' for distribution details. > R is a collaborative project with many contributors. > Type 'contributors()' for more information. > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for a HTML browser interface to help. > Type 'q()' to quit R. > [Previously saved workspace restored] > > source("convert.r") > > convert("transf") > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file `transf.cgm' > > > ----------------------------------- > Have i done some mistakes?Or i am missing some files? > Please assist. > Rgs, > Orlando. > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
Hi- As far as I know, some of the error messages results from the fact that you either did not install the package or did not load the package. If you did not install the package, you can install from R's GUI (my experiences are based on the Windows Version), and load them by type library (packagename). If you have already installed them, just type library (packagename) and you will be good to go. For your specific case, after you started R, just type library(maptools), and you will be able to use all the functions such as read.shape, Map2poly, plotpolys, etc. Quoting Orlando Zacarias <si-opz at dsv.su.se>:>> Hi once again,> Now i have been trying to run the R changed example from Maptools package > manual, and errors occur underlined bellow. It is really troublesome....> Please assist,> Orlando.> ---------------------------------------------------> shp <- try(library(shapefiles))> Error in library(maptools) : There is no package called 'shapefiles'> > if (class(shp) != "try-error") {> + ShapeDir <- system.file("shapes", package="maptools")[1]> + try1 <- read.shapefile(paste(ShapeDir, "shapes", sep="/"))> + shppolys <- shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))> + plotpolys(shppolys)> + title(main="Polygons for Vermani from shapefiles package")> + }> >> > try2 <- read.shape(system.file("shapes/Vermani.shp",> + package="maptools/man")[1])> Error: couldn't find function "read.shape"> > mappolys <- Map2poly(try2, as.character(try2$att.data$NEIGNO))> Error: couldn't find function "Map2poly"> > plotpolys(mappolys)> Error: couldn't find function "plotpolys"> > title(main="Polygons for Vermani from maptools package")> Error in title(main = "Polygons for Vermani from maptools package") :> plot.new has not been called yet> > if (class(shp) != "try-error") {> + plotpolys(shppolys)> + plotpolys(mappolys, add=TRUE, border="red", lty="dotted")> + title(main="Polygons for Vermani overplotted from both packages")> + }> ------------------------------------------------------
> > ----- Original Message ----- > From: "Orlando Zacarias" <si-opz at dsv.su.se> > To: <cdeclercq at nordnet.fr> > Cc: <r-sig-geo at stat.math.ethz.ch>; <r-help at stat.math.ethz.ch> > Sent: Thursday, October 23, 2003 6:56 PM > Subject: RE: [R] adjacency matrix > > > > Hi once again, > Now i have been trying to run the R changed example from Maptools > package manual, and errors occur underlined bellow. It is really > troublesome.... > Please assist, > Orlando. > --------------------------------------------------- > shp <- try(library(shapefiles)) > Error in library(maptools) : There is no package called 'shapefiles'The message is clear!> > if (class(shp) != "try-error") { > + ShapeDir <- system.file("shapes", package="maptools")[1] > + try1 <- read.shapefile(paste(ShapeDir, "shapes", sep="/")) > + shppolys <- shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO)) > + plotpolys(shppolys) > + title(main="Polygons for Vermani from shapefiles package") > + } > > > > try2 <- read.shape(system.file("shapes/Vermani.shp", > + package="maptools/man")[1]) > Error: couldn't find function "read.shape" > > mappolys <- Map2poly(try2, as.character(try2$att.data$NEIGNO)) > Error: couldn't find function "Map2poly" > > plotpolys(mappolys) > Error: couldn't find function "plotpolys" > > title(main="Polygons for Vermani from maptools package") > Error in title(main = "Polygons for Vermani from maptools package") : > plot.new has not been called yet > > if (class(shp) != "try-error") { > + plotpolys(shppolys) > + plotpolys(mappolys, add=TRUE, border="red", lty="dotted") > + title(main="Polygons for Vermani overplotted from both packages") > + } > ------------------------------------------------------Did you forget:> library(maptools)before that? Christophe