Skip to content

Commit

Permalink
(1) inp_to_file uses current working directory as default, (2) 'print…
Browse files Browse the repository at this point in the history
…' statements are substituted by 'message' (https://stackoverflow.com/a/36700294)
  • Loading branch information
dleutnant committed Mar 16, 2019
1 parent 1814daa commit 869b842
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
25 changes: 12 additions & 13 deletions R/inp_to_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ sections_to_shp <- function(x, name, path_out) {

} else {

message("section %s is missing", section)
message(sprintf("section %s is missing", section))
}
}

print(paste0("*.shp files were written to: ", shape_dir))
message(sprintf("*.shp files were written to %s", shape_dir))
}

#write_section_if_in_list <- function(x, section, conversion_function, file, ...)
Expand Down Expand Up @@ -166,13 +166,12 @@ options_to_txt <- function(x, name, path_out) {
# unlist and save txt file
writeLines(unlist(options_txt), con = file.path(path_out, paste0("txt/", name, "_options.txt")))

print(paste0("*.txt file was written to: ", path_out, "/txt"))
message(sprintf("*.txt file was written to %s/txt", path_out))
} else {
print("section options is missing")
message("section options is missing")
}
}


#' conversion helper
#' @keywords internal
curves_to_txt <- function(x, name, path_out) {
Expand Down Expand Up @@ -206,10 +205,9 @@ curves_to_txt <- function(x, name, path_out) {
unlist(lapply(list_of_curves, "[[", 1, 1)), ".txt"),
sep = " ", dec = ".", col.names = F, row.names = F, quote = F)


print(paste0("curve.txt files were written to:", path_out, "/txt"))
message(sprintf("curve.txt files were written to %s/txt", path_out))
} else {
print("section curves is missing")
message("section curves is missing")
}
}

Expand Down Expand Up @@ -246,22 +244,23 @@ timeseries_to_dat <- function(x, name, path_out) {
}
}

print(paste0("timeseries.dat files were written to: ", path_out, "/dat"))

message(sprintf("timeseries.dat files were written to %s/dat", path_out))
} else {
print("section timeseries is missing")
message("section timeseries is missing")
}
}

#' Convert SWMM's .inp to .shp and txt files
#'
#' @param x An object of class inp.
#' @param name Give a name for the current model, e.g. "Example1".
#' @param path_out Writeable directory name where to save the converted files. Folders: dat, shp and txt will be created if not existent.
#' @param path_out Writeable directory name where to save the converted files.
#' Folders: dat, shp and txt will be created if not existent. Default is the
#' current working directory of the R process.
#' @return .dat, .shp and/or .txt files.
#' @rdname inp_to_files
#' @export
inp_to_files <- function(x, name, path_out) {
inp_to_files <- function(x, name, path_out = getwd()) {
# check class
stopifnot(inherits(x, "inp"))

Expand Down
6 changes: 4 additions & 2 deletions man/inp_to_files.Rd

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

0 comments on commit 869b842

Please sign in to comment.