I think this is a bug, but not sure enough to open a pull request because I'm still understanding this script.
When executing build-json.sh, I receive an error in the subsequent build-json.Rout (please note this is modified to report number of arguments through the script):
R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
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.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> args <- commandArgs(TRUE)
> print(args)
[1] "9"
> runNumber <- as.numeric(args[1])
> print(runNumber)
[1] 9
> runRange <- c(((runNumber - 1) * 100) + 1, runNumber * 100)
> print(runRange)
[1] 801 900
>
> ## check out buildings in 7709.02, 8214.02 - seems to be missing buildings
> ## "Partially outside City Boundary"
> ## also broke: 3817, 605
>
>
> # ---------------------------------------------------------------------------- #
> # A script to add features and aggregate data for Chicago buildings
> #
> # Author: Nick Lucius
> # ---------------------------------------------------------------------------- #
>
> library(data.table, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
> library(rgeos, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
rgeos version: 0.3-28, (SVN revision 572)
GEOS runtime version: 3.6.1-CAPI-1.10.1 r0
Linking to sp version: 1.3-1
Polygon checking: TRUE
> library(sp, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
> library(rgdal, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
rgdal: version: 1.3-4, (SVN revision 766)
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/tschenk/Documents/R/win-library/3.5/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/tschenk/Documents/R/win-library/3.5/rgdal/proj
Linking to sp version: 1.3-1
> library(leaflet, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
> library(RSocrata, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
> library(plyr, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
> library(raster, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
Attaching package: 'raster'
The following object is masked from 'package:data.table':
shift
> library(stringr, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
> library(jsonlite, lib.loc = "C:/Users/tschenk/Documents/R/win-library/3.5")
>
> # ---------------------------------------------------------------------------- #
> # Import Data
> # ---------------------------------------------------------------------------- #
>
> source("R/tracts.R")
OGR data source with driver: GeoJSON
Source: "C:\Users\tschenk\Documents\git\buildings\data\geojson\tracts.geojson", layer: "tracts"
with 801 features
It has 9 fields
> source("R/functions.R")
>
> # ---------------------------------------------------------------------------- #
> # Initialize bldgList (will become building.json)
> # ---------------------------------------------------------------------------- #
>
> which(tracts$name10 %in% c("7709.02", "8214.02", "3817"))
[1] 181 313 415
> # [1] 181 313 415
> tractsList <- tracts$name10[c(1:180,182:312,314:414,416:724,726:801)]
> tractsList <- tractsList[runRange[1]:runRange[2]]
>
> # small focus in district 11
> # which(tracts$name10 == "2608")
> # tractsList <- tracts$name10[736]
>
> buildJSON(tracts, tractsList)
Error in ogrListLayers(dsn = dsn) : Cannot open data source
Calls: buildJSON ... withVisible -> eval -> eval -> readOGR -> ogrListLayers
Execution halted
When walking through the steps, this occurred because tractsList <- tractsList[runRange[1]:runRange[2]] generated NAs since it was just out-of-range.
I locally modified the build-json.sh script to only have 8 arguments, e.g.,
#!/bin/bash
R CMD BATCH '--args 1' R/build-json.R
R CMD BATCH '--args 2' R/build-json.R
R CMD BATCH '--args 3' R/build-json.R
R CMD BATCH '--args 4' R/build-json.R
R CMD BATCH '--args 5' R/build-json.R
R CMD BATCH '--args 6' R/build-json.R
R CMD BATCH '--args 7' R/build-json.R
R CMD BATCH '--args 8' R/build-json.R
exit 0
The result did not produce Cannot open data source error.
I think this is a bug, but not sure enough to open a pull request because I'm still understanding this script.
When executing
build-json.sh
, I receive an error in the subsequentbuild-json.Rout
(please note this is modified to report number of arguments through the script):When walking through the steps, this occurred because
tractsList <- tractsList[runRange[1]:runRange[2]]
generatedNA
s since it was just out-of-range.I locally modified the
build-json.sh
script to only have 8 arguments, e.g.,The result did not produce
Cannot open data source
error.