-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field name with parentheses or spaces #65
Comments
This could be rather simple to fix. Please can you take a look which characters get replaced? If it is only () or also [], etc. Any idea if it will happen if you try to load the data using sp package with |
Presumably, all non-alphanumeric characters except for underscores will be replaced by dots. When the check.names option is FALSE, read.table and data.frame will also behave in the same way. If the substitution results in the same name as the other column name, digits are appended to the end, so the substitution alone does not tell if it is a correct column name or not. # test1.R
d <- data.frame(`x `=1, `x(`=2, `x_`=3, `x=`=4, `x@`=5)
names(d) $ rscript test1.R
[1] "x." "x..1" "x_" "x..2" "x..3" # test2.R
d <- data.frame(`x `=1, `x(`=2, `x_`=3, `x=`=4, `x@`=5, check.names=FALSE)
names(d) $ rscript test2.R
[1] "x " "x(" "x_" "x=" "x@" # test3.R
library(rgdal)
ogrInfo("sample.gpkg", layer="sample") $ rscript test3.R
Loading required package: sp
rgdal: version: 1.4-8, (SVN revision 845)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/username/bin/R-Portable/App/R-Portable/librar GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/username/bin/R-Portable/App/R-Portable/libr Linking to sp version: 1.3-2
Source: "C:\Users\username\Desktop\GIS\sample.gpkg", layer: "sample"
Driver: GPKG; number of rows: 5
Feature type: wkbPoint with 2 dimensions
Extent: (-0.02076547 -0.2517086) - (0.474755 0.1368101)
CRS: +proj=longlat +datum=WGS84 +no_defs
Number of fields: 5
name type length typeName
1 x 0 0 Integer
2 x( 0 0 Integer
3 x_ 0 0 Integer
4 x= 0 0 Integer
5 x@ 0 0 Integer # test4.R
library(sf)
pt <- st_read("sample.gpkg", layer="sample")
names(pt) $ rscript test4.R
Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
Reading layer `sample' from data source `C:\Users\username\Desktop\GIS\sample.gpkg' using driver `GPKG'
Simple feature collection with 5 features and 5 fields
geometry type: POINT
dimension: XY
bbox: xmin: -0.02076547 ymin: -0.2517086 xmax: 0.474755 ymax: 0.1368101
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
[1] "x." "x..1" "x_" "x..2" "x..3" "geometry" # test5.R
library(sf)
pt <- st_read("sample.gpkg", layer="sample", as_tibble=TRUE)
names(pt) $ rscript test5.R
Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
Reading layer `sample' from data source `C:\Users\username\Desktop\GIS\sample.gpkg' using driver `GPKG'
Simple feature collection with 5 features and 5 fields
geometry type: POINT
dimension: XY
bbox: xmin: -0.02076547 ymin: -0.2517086 xmax: 0.474755 ymax: 0.1368101
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
[1] "x." "x..1" "x_" "x..2" "x..3" "geometry" # test6.R
library(rgdal)
pt <- readOGR("sample.gpkg", layer="sample")
names(pt) $ rscript test6.R
Loading required package: sp
rgdal: version: 1.4-8, (SVN revision 845)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/username/bin/R-Portable/App/R-Portable/library/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/username/bin/R-Portable/App/R-Portable/library/rgdal/proj
Linking to sp version: 1.3-2
OGR data source with driver: GPKG
Source: "C:\Users\username\Desktop\GIS\sample.gpkg", layer: "sample"
with 5 features
It has 5 fields
[1] "x." "x..1" "x_" "x..2" "x..3" |
In sf version 1.0-8, there will be an extra argument in st_read() to optionally pass name checking (sf:#1916). In that way the names that originally come from the user data will be preserved, even if they contain special characters. It will be good to consider adding it in the future in the parser for |
Hi,
If the attribute name contains parentheses or spaces, R replaces them with dots.
However,
Layer[[Field]]
is null because the name of the field before the replacement is used.the log is
The text was updated successfully, but these errors were encountered: