Error in rgdal::OSRIsProjected(obj) : Can't parse user input string - r

I have a SpatialPolygonsDataFrame dataset called election which includes US County polygons and some attributes. I tried to summary this dataset. But there is an error.
summary(election)
Error in rgdal::OSRIsProjected(obj) : Can't parse user input string
In addition: Warning message: In wkt(obj) : CRS object has no comment
The same error also occur when I plot(election).
No error generated when I name(election) and head(election).

I know this is late, and hopefully you will have found a solution by now, but I ran across the same issue on what I assume is the same dataset/shapefile, so I'm adding this in case anyone comes across the same problem.
Getting the error:
Error in rgdal::OSRIsProjected(obj) : Can't parse user input string
In addition: Warning message:
In wkt(obj) : CRS object has no comment
usually means that the CRS (proj4string for sp objects), or some other aspect of the spdf is invalid. In this case, it actually seems to just be a simple typo; there's just a missing space.
The proj4string, +proj=lcc+lon_0=90w +lat_1=20n +lat_2=60n
should be, +proj=lcc +lon_0=90w +lat_1=20n +lat_2=60n
Note the missing space between "lcc" and "+lon_0=90w"!
However, using proj4string(x)<- fails, again because the p4s is invalid, but we can set the argument manually with
election#proj4string#projargs <- "+proj=lcc +lon_0=90w +lat_1=20n +lat_2=60n"
Hope this helps anyone who seems to have this issue! I've noticed all the issues come from presumably the same dataset.
Best,

Related

Warning message within R function seems to make the function not work?

Using the syuzhet package in R, the following works but returns a warning message:
object <- get_text_as_string("path/name.txt")
When I put this in a function, it returns the same warning error but does NOT change the value of object:
gen <- function(file){
object <- get_text_as_string(file)
}
gen("path/name.txt")
This is the warning message, if it matters:
Warning message:
In readLines(path_to_file) :
incomplete final line found on 'path/name.txt'
...but again, I get that from get_text_as_string() when used outside of the function, but it DOES change the value of object.
Anyone have any advice? There must be something I don't understand about functions?
(I've looked for similar questions/answers, if I've missed the right one I'd be happy to just be directed there.)

Error in validityMethod(as(object, superClass)) : object 'Matrix_validate' not found

I just try to use :
scRNA <- FindNeighbors(scRNA, dims = pc.num)
and
scRNA.counts <- Read10X(data.dir = "filtered_feature_bc_matrix")
and both of them gives error like :
Error in validityMethod(as(object, superClass)) : object 'Matrix_validate' not found
I guess these code totally run well in other's computer
so I wonder what's wrong with my code and how to fix it ?
Indeed, to solve the problem for you, it should be sufficient to do what #Mikael Jagan says:
update.packages("Matrix")
2nd thought: The above may not solve the problem entirely:
As there are other packages involved, some of these may have to be re-installed (after the updating of Matrix).
Can you post the output (or good summary of that if it's too long) of
traceback()
immediately after producing the error you are seeing?

About my GIS question in R (from readShapePoly to sf::st_read)

I am needed to use sf package command, because readShapePoly commnad will be erased. That's neer future I know... So I want to change my code from route
thata readShapePloy to route sf::st_read. But I cannot write correct code. So I want to correct code and I am very happy, if u show correct sf package command. My now command below, thx...(I am sorry to my poor English skill,Plz over come it...)
In R, I wrote code again and again for ex, on sf::st_read command. But that show error again and again...code below nd error message below too
usa_state <- readShapePoly("usa_state.shp", IDvar = "STATE_CODE")
That is ok, but I know to change that code neer future, cuz this command is erased in neer future. So Plz show me command thata route of sf package.I tried below code but I know this is not understandable in R.
usa_state = sf::st_read("usa_state.shp", layer = "STATE_CODE")
bad code...Plz shw me correct coding!Error occured now am I...
Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
SQL execution failed, cannot open layer.
In addition: Warning message:
In CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
GDAL Error 1: SQL Expression Parsing Error: syntax error, unexpected
identifier, expecting SELECT or '('. Occurred around : "STATE_CODE"
You're almost there with usa_state = sf::st_read("usa_state.shp", layer = "STATE_CODE").
I'm guessing that STATE_CODE is a field in the usa_state.shp shapefile. You don't need to supply any field names to the st_read() function. Just use:
library(sf)
usa_state = st_read("usa_state.shp")
You'll need to make sure that the usa_state.shp file (and its associated files) are in your current working directory, or you'll need to use the full path:
usa_state = st_read("/path/to/usa_state.shp")
The sf package is well worth getting to know. It's made all of my spatial work in R much easier.

Cannot load a shapefile in R "Error: no features found"

I'm trying to read the shapefile that you can download with this url.
I have a code similar to the next one to download automatically the files:
library("raster")}
url<-"http://www6.gipuzkoa.eus/CATASTRO/Planos/ZIP-A098.zip"
downloader::download(url, dest=paste0(getwd(),"/","my_file.zip"), mode="wb",quiet=T)
zipped_shape_names<-c("098_HELBIDE_SHP/ATRIBUTOAK-A098.cpg","098_HELBIDE_SHP/ATRIBUTOAK-A098.dbf","098_HELBIDE_SHP/ATRIBUTOAK-A098.shp","098_HELBIDE_SHP/ATRIBUTOAK-A098.shx")
unzip("my_file.zip", files=zipped_shape_names)
my_shape<-raster::shapefile("098_HELBIDE_SHP/ATRIBUTOAK-A098.shp")
But what I obtain is the following error:
Error in rgdal::readOGR(dirname(x), fn, stringsAsFactors = stringsAsFactors, :
no features found
In addition: Warning messages:
1: In .local(x, ...) : .prj file is missing
2: In ogrFIDs(dsn = dsn, layer = layer) : no features found
You can access to the original web page by this link and pressing "Descargar planos"
I don't have this problem with others areas, just with this and another one, but I don't know what is happening with this specific area.
Any help will be appreciated.
The error message is quite clear. no features found means that your shapefile is empty. You can check this in multiple ways.
One is to add your shapefile in Q-Gis or any other GIS-software tool. In the case of Q-GIS your shapefile will pop-up in the layers pane, but you won't see any features.
It is also possible to check the .dbf file in R:
library(foreign)
read.dbf("098_HELBIDE_SHP/ATRIBUTOAK-A098.dbf")
The .dbf should contain as many rows as there are features. In your case None.
Simpler code would be
library(raster)
url<-"http://www6.gipuzkoa.eus/CATASTRO/Planos/ZIP-A098.zip"
download.file(url, dest="my_file.zip")
unzip("my_file.zip")
s <- raster::shapefile("098_HELBIDE_SHP/ATRIBUTOAK-A098.shp")
Clearly that file is empty. However, it works for this file:
s <-raster::shapefile("098_LANDALUR_SHP/LANDALUR-PARTZELAK-A098.shp")

ASCII files in R

I have some data that's in an ASCII format. I'm not allowed to put the data online so unfortunately I can't post it on here (although I realize that it would be the most helpful that way). The code I'm using now to get the ASCII data in R is...
library(SAScii)
parse.SAScii("file.txt")
But then I get this error:
Error in firstline:lastline : NA/NaN argument
In addition: Warning message:
In min(a[a > firstline]) : no non-missing arguments to min; returning Inf
I can't find anything online about this error and I was hoping someone might be able to point me to what I could be doing wrong. I know this question is kind of vague but I'm just hoping someone can direct me in the right direction.
Try this to read lines from a file with that name in the working directory:
my.input <- readLines("file.txt")
head(my.input)
str(my.input)

Resources