Skip to content

Commit

Permalink
Merge branch 'master' into gpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer authored May 20, 2020
2 parents 76cf287 + c6d97db commit 9767a31
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* `st_write` writes non-spatial tables when given a plain `data.frame` or `tbl_df`; #1345

* the default for `stringsAsFactors` in `st_read` and `st_sf` is FALSE for R version > 4.1.0

# version 0.9-3

* `st_is_valid` is a generic
Expand Down
20 changes: 14 additions & 6 deletions R/read.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
sf_stringsAsFactors = function() {
if (getRversion() < "4.1.0")
default.stringsAsFactors()
else
FALSE
}

set_utf8 = function(x) {
n = names(x)
Encoding(n) = "UTF-8"
Expand Down Expand Up @@ -44,9 +51,9 @@ set_utf8 = function(x) {
#' of LineString and MultiLineString, or of Polygon and MultiPolygon, convert
#' all to the Multi variety; defaults to \code{TRUE}
#' @param stringsAsFactors logical; logical: should character vectors be
#' converted to factors? The `factory-fresh' default is \code{TRUE} for
#' \code{st_read} and \code{FALSE} for \code{read_sf}, but this can be changed
#' globally by e.g. the R command \code{options(stringsAsFactors = FALSE)}.
#' converted to factors? Default for \code{read_sf} or R version >= 4.1.0 is
#' \code{FALSE}, for \code{st_read} and R version < 4.1.0 equal to
#' \code{default.stringsAsFactors()}
#' @param int64_as_string logical; if TRUE, Int64 attributes are returned as
#' string; if FALSE, they are returned as double and a warning is given when
#' precision is lost (i.e., values are larger than 2^53).
Expand Down Expand Up @@ -134,7 +141,8 @@ st_read.default = function(dsn, layer, ...) {
}

process_cpl_read_ogr = function(x, quiet = FALSE, ..., check_ring_dir = FALSE,
stringsAsFactors = ifelse(as_tibble, FALSE, default.stringsAsFactors()), geometry_column = 1, as_tibble = FALSE) {
stringsAsFactors = ifelse(as_tibble, FALSE, sf_stringsAsFactors()),
geometry_column = 1, as_tibble = FALSE) {

which.geom = which(vapply(x, function(f) inherits(f, "sfc"), TRUE))

Expand Down Expand Up @@ -199,8 +207,8 @@ process_cpl_read_ogr = function(x, quiet = FALSE, ..., check_ring_dir = FALSE,
#' to the current working directory (see \link{getwd}). "Shapefiles" consist of several files with the same basename
#' that reside in the same directory, only one of them having extension \code{.shp}.
#' @export
st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet = FALSE, geometry_column = 1L, type = 0,
promote_to_multi = TRUE, stringsAsFactors = default.stringsAsFactors(),
st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet = FALSE, geometry_column = 1L,
type = 0, promote_to_multi = TRUE, stringsAsFactors = sf_stringsAsFactors(),
int64_as_string = FALSE, check_ring_dir = FALSE, fid_column_name = character(0),
drivers = character(0), wkt_filter = character(0)) {

Expand Down
4 changes: 2 additions & 2 deletions R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ list_column_to_sfc = function(x) {
#' @param crs coordinate reference system: integer with the EPSG code, or character with proj4string
#' @param agr character vector; see details below.
#' @param row.names row.names for the created \code{sf} object
#' @param stringsAsFactors logical; logical: should character vectors be converted to factors? The `factory-fresh' default is \code{TRUE}, but this can be changed by setting \code{options(stringsAsFactors = FALSE)}.
#' @param stringsAsFactors logical; see \link{st_read}
#' @param precision numeric; see \link{st_as_binary}
#' @param sf_column_name character; name of the active list-column with simple feature geometries; in case
#' there is more than one and \code{sf_column_name} is \code{NULL}, the first one is taken.
Expand All @@ -215,7 +215,7 @@ list_column_to_sfc = function(x) {
#' df <- st_sf(id = 1:nrows, geometry = geometry)
#' @export
st_sf = function(..., agr = NA_agr_, row.names,
stringsAsFactors = default.stringsAsFactors(), crs, precision,
stringsAsFactors = sf_stringsAsFactors(), crs, precision,
sf_column_name = NULL, check_ring_dir = FALSE, sfc_last = TRUE) {
x = list(...)
if (length(x) == 1L && (inherits(x[[1L]], "data.frame") || (is.list(x) && !inherits(x[[1L]], "sfc"))))
Expand Down
4 changes: 2 additions & 2 deletions man/sf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/st_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9767a31

Please sign in to comment.