Skip to content

Commit

Permalink
Use !missing(argument) in wbt_ functions for default options affect…
Browse files Browse the repository at this point in the history
…ing settings.json opengeos#67
  • Loading branch information
brownag committed Mar 31, 2022
1 parent ca55f6f commit 7157d5e
Show file tree
Hide file tree
Showing 22 changed files with 2,090 additions and 2,073 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# whitebox 2.1.3

* Updates to fix issues with permissions to write _settings.jso*n_

* Generated `whitebox_tools` commands no longer include flags for default arguments

# whitebox 2.1.2

* Fixes regression in checking "Demo" vignette on CRAN
Expand Down
13 changes: 12 additions & 1 deletion PY2R/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,18 @@ def function_block(line, ff):
ff.write(" }" + "\n")
elif "verbose" not in item:
para = item.split("=")[0]
if '"' not in para:
if '"' not in para and "wd" in para or "compress_rasters" in para:
ff.write(" if (!missing(" + para + ")) {" + "\n")
ff.write(
' args <- paste(args, paste0("--'
+ para
+ '=", '
+ para
+ "))"
+ "\n"
)
ff.write(" }" + "\n")
elif '"' not in para:
ff.write(" if (!is.null(" + para + ")) {" + "\n")
ff.write(
' args <- paste(args, paste0("--'
Expand Down
104 changes: 52 additions & 52 deletions PY2R/scripts/data_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ wbt_add_point_coordinates_to_table <- function(input, wd=NULL, verbose_mode=FALS
wbt_init()
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "add_point_coordinates_to_table"
Expand All @@ -43,10 +43,10 @@ wbt_clean_vector <- function(input, output, wd=NULL, verbose_mode=FALSE, compres
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "clean_vector"
Expand All @@ -72,10 +72,10 @@ wbt_convert_nodata_to_zero <- function(input, output, wd=NULL, verbose_mode=FALS
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "convert_nodata_to_zero"
Expand All @@ -101,10 +101,10 @@ wbt_convert_raster_format <- function(input, output, wd=NULL, verbose_mode=FALSE
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "convert_raster_format"
Expand Down Expand Up @@ -142,10 +142,10 @@ wbt_csv_points_to_vector <- function(input, output, xfield=0, yfield=1, epsg=NUL
if (!is.null(epsg)) {
args <- paste(args, paste0("--epsg=", epsg))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "csv_points_to_vector"
Expand Down Expand Up @@ -175,10 +175,10 @@ wbt_export_table_to_csv <- function(input, output, headers=TRUE, wd=NULL, verbos
if (headers) {
args <- paste(args, "--headers")
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "export_table_to_csv"
Expand Down Expand Up @@ -208,10 +208,10 @@ wbt_fix_dangling_arcs <- function(input, output, dist="", wd=NULL, verbose_mode=
if (!is.null(dist)) {
args <- paste(args, paste0("--dist=", dist))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "fix_dangling_arcs"
Expand Down Expand Up @@ -243,10 +243,10 @@ wbt_join_tables <- function(input1, pkey, input2, fkey, import_field, wd=NULL, v
args <- paste(args, paste0("--input2=", wbt_file_path(input2)))
args <- paste(args, paste0("--fkey=", wbt_file_path(fkey)))
args <- paste(args, paste0("--import_field=", wbt_file_path(import_field)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "join_tables"
Expand All @@ -272,10 +272,10 @@ wbt_lines_to_polygons <- function(input, output, wd=NULL, verbose_mode=FALSE, co
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "lines_to_polygons"
Expand Down Expand Up @@ -309,10 +309,10 @@ wbt_merge_table_with_csv <- function(input, pkey, csv, fkey, import_field=NULL,
if (!is.null(import_field)) {
args <- paste(args, paste0("--import_field=", import_field))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "merge_table_with_csv"
Expand All @@ -338,10 +338,10 @@ wbt_merge_vectors <- function(inputs, output, wd=NULL, verbose_mode=FALSE, compr
args <- ""
args <- paste(args, paste0("--inputs=", wbt_file_path(inputs)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "merge_vectors"
Expand Down Expand Up @@ -369,10 +369,10 @@ wbt_modify_no_data_value <- function(input, new_value="-32768.0", wd=NULL, verbo
if (!is.null(new_value)) {
args <- paste(args, paste0("--new_value=", new_value))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "modify_no_data_value"
Expand Down Expand Up @@ -402,10 +402,10 @@ wbt_multi_part_to_single_part <- function(input, output, exclude_holes=TRUE, wd=
if (exclude_holes) {
args <- paste(args, "--exclude_holes")
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "multi_part_to_single_part"
Expand Down Expand Up @@ -443,10 +443,10 @@ wbt_new_raster_from_base <- function(base, output, value="nodata", data_type="fl
if (!is.null(cell_size)) {
args <- paste(args, paste0("--cell_size=", cell_size))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "new_raster_from_base"
Expand All @@ -472,10 +472,10 @@ wbt_polygons_to_lines <- function(input, output, wd=NULL, verbose_mode=FALSE, co
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "polygons_to_lines"
Expand All @@ -499,10 +499,10 @@ wbt_print_geo_tiff_tags <- function(input, wd=NULL, verbose_mode=FALSE, compress
wbt_init()
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "print_geo_tiff_tags"
Expand All @@ -528,10 +528,10 @@ wbt_raster_to_vector_lines <- function(input, output, wd=NULL, verbose_mode=FALS
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "raster_to_vector_lines"
Expand All @@ -557,10 +557,10 @@ wbt_raster_to_vector_points <- function(input, output, wd=NULL, verbose_mode=FAL
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "raster_to_vector_points"
Expand All @@ -586,10 +586,10 @@ wbt_raster_to_vector_polygons <- function(input, output, wd=NULL, verbose_mode=F
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "raster_to_vector_polygons"
Expand All @@ -613,10 +613,10 @@ wbt_reinitialize_attribute_table <- function(input, wd=NULL, verbose_mode=FALSE,
wbt_init()
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "reinitialize_attribute_table"
Expand All @@ -642,10 +642,10 @@ wbt_remove_polygon_holes <- function(input, output, wd=NULL, verbose_mode=FALSE,
args <- ""
args <- paste(args, paste0("--input=", wbt_file_path(input)))
args <- paste(args, paste0("--output=", wbt_file_path(output)))
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "remove_polygon_holes"
Expand Down Expand Up @@ -675,10 +675,10 @@ wbt_set_nodata_value <- function(input, output, back_value=0.0, wd=NULL, verbose
if (!is.null(back_value)) {
args <- paste(args, paste0("--back_value=", back_value))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "set_nodata_value"
Expand Down Expand Up @@ -708,10 +708,10 @@ wbt_single_part_to_multi_part <- function(input, output, field=NULL, wd=NULL, ve
if (!is.null(field)) {
args <- paste(args, paste0("--field=", field))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "single_part_to_multi_part"
Expand Down Expand Up @@ -753,10 +753,10 @@ wbt_vector_lines_to_raster <- function(input, output, field="FID", nodata=TRUE,
if (!is.null(base)) {
args <- paste(args, paste0("--base=", base))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "vector_lines_to_raster"
Expand Down Expand Up @@ -802,10 +802,10 @@ wbt_vector_points_to_raster <- function(input, output, field="FID", assign="last
if (!is.null(base)) {
args <- paste(args, paste0("--base=", base))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "vector_points_to_raster"
Expand Down Expand Up @@ -847,10 +847,10 @@ wbt_vector_polygons_to_raster <- function(input, output, field="FID", nodata=TRU
if (!is.null(base)) {
args <- paste(args, paste0("--base=", base))
}
if (!is.null(wd)) {
if (!missing(wd)) {
args <- paste(args, paste0("--wd=", wd))
}
if (!is.null(compress_rasters)) {
if (!missing(compress_rasters)) {
args <- paste(args, paste0("--compress_rasters=", compress_rasters))
}
tool_name <- "vector_polygons_to_raster"
Expand Down
Loading

0 comments on commit 7157d5e

Please sign in to comment.