Skip to content

Commit

Permalink
Use scalar operators and outer negation in if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Mar 17, 2024
1 parent 6959040 commit 35855b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/otp-isochrone-batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ otp_process_results_iso <- function(text, fromID){
response$id <- seq(1, nrow(response))
response$fromPlace <- fromID

if (any(!sf::st_is_valid(response))) {
if (!all(sf::st_is_valid(response))) {
suppressMessages(suppressWarnings(response <- sf::st_make_valid(response)))
}

Expand Down
10 changes: 5 additions & 5 deletions R/otp-plan.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ otp_plan <- function(otpcon = NA,
checkmate::assert_logical(distance_balance, len = 1, null.ok = FALSE)
checkmate::assert_logical(get_elevation, len = 1, null.ok = FALSE)

if (distance_balance & (ncores > 1)) {
if (distance_balance && (ncores > 1)) {
if (is.null(fromID)) {
stop("Distance balancing changes the order of the output, so fromID must not be NULL")
}
Expand Down Expand Up @@ -187,13 +187,13 @@ otp_plan <- function(otpcon = NA,
nrfp <- nrow(fromPlace)
nrtp <- nrow(toPlace)
if (nrfp != nrtp) {
if (nrfp > nrtp & nrtp == 1) {
if (nrfp > nrtp && nrtp == 1) {
toPlace <- toPlace[rep(1, times = nrfp), ]
if (!is.null(toID)) {
toID <- toID[rep(1, times = nrfp)]
}
message("repeating toPlace to match length of fromPlace")
} else if (nrtp > nrfp & nrfp == 1) {
} else if (nrtp > nrfp && nrfp == 1) {
fromPlace <- fromPlace[rep(1, times = nrtp), ]
if (!is.null(fromID)) {
fromID <- fromID[rep(1, times = nrtp)]
Expand All @@ -204,7 +204,7 @@ otp_plan <- function(otpcon = NA,
}
}

if (distance_balance & (ncores > 1)) {
if (distance_balance && (ncores > 1)) {
dists <- geodist::geodist(fromPlace, toPlace, paired = TRUE)

# Remove 0m pairs as OTP will fail on them anyway
Expand Down Expand Up @@ -243,7 +243,7 @@ otp_plan <- function(otpcon = NA,

if (otpcon$otp_version >= 2) {
# maxWalkDistance causes itinaries to fail
if (mode == "CAR" | grepl("TRANSIT", mode)) {
if (mode == "CAR" || grepl("TRANSIT", mode)) {

Check warning on line 246 in R/otp-plan.R

View check run for this annotation

Codecov / codecov/patch

R/otp-plan.R#L246

Added line #L246 was not covered by tests
query$maxWalkDistance <- NULL
}
}
Expand Down
12 changes: 6 additions & 6 deletions R/otp-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ otp_stop <- function(warn = TRUE, kill_all = TRUE) {
)
}

if (checkmate::testOS("linux") | checkmate::testOS("mac")) {
if (checkmate::testOS("linux") || checkmate::testOS("mac")) {
message("The following Java instances have been found:")
system("ps -A |grep java")
if (!kill_all) {
Expand Down Expand Up @@ -456,7 +456,7 @@ otp_checks <- function(otp = NULL,
chkG <- file.exists(paste0(dir, "/graphs/", router, "/Graph.obj"))
chkg <- file.exists(paste0(dir, "/graphs/", router, "/graph.obj"))

if(!(chkG | chkg)){
if(!(chkG || chkg)){
stop("File does not exist")
}

Expand Down Expand Up @@ -525,7 +525,7 @@ otp_check_java <- function(otp_version = 1.5) {
}

if (otp_version < 2) {
if (java_version >= 1.8 & java_version < 1.9) {
if (java_version >= 1.8 && java_version < 1.9) {
message("You have the correct version of Java for OTP 1.x")
return(TRUE)
}
Expand All @@ -544,8 +544,8 @@ otp_check_java <- function(otp_version = 1.5) {
return(FALSE)
}

if (otp_version >= 2 & otp_version <= 2.1) {
if (java_version >= 1.8 & java_version < 1.9) {
if (otp_version >= 2 && otp_version <= 2.1) {
if (java_version >= 1.8 && java_version < 1.9) {
warning("You have OTP 2.0 or 2.1 but the version of Java for OTP 1.x")
return(FALSE)
}
Expand All @@ -565,7 +565,7 @@ otp_check_java <- function(otp_version = 1.5) {
}

if (otp_version >= 2.2) {
if (java_version >= 1.8 & java_version < 1.9) {
if (java_version >= 1.8 && java_version < 1.9) {
warning("You have OTP 2.2+ but the version of Java for OTP 1.x")
return(FALSE)
}
Expand Down
2 changes: 1 addition & 1 deletion R/utility-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ parse_leg <- function(leg,
leg$from <- NULL
leg$to <- NULL

if (get_elevation | full_elevation) {
if (get_elevation || full_elevation) {
elevation <- purrr::map(leg$steps, parse_elevation)
} else {
elevation <- list(NULL)
Expand Down

0 comments on commit 35855b8

Please sign in to comment.