저는 R에 익숙하지 않아 일부 지리적 출력으로 함수를 만들려고합니다. 지도 제목과 같은 특정 매개 변수에 대한 기본값을 설정하는 if/else 문을 포함하려고하지만 동일한 문제가 반복적으로 발생했습니다. 다른 사람들도 같은 문제를 가지고 있지만 그들의 질문이 나를 도와주지 않은 응답을 가지고 있습니다.if/else 문에서 중괄호 관련 문제
다음은 현재 발생하고있는 오류는 물론 단순화 된 코드입니다.
my_function <- function(x, y, map.title, a, ...){
neighbours <- spdep::poly2nb(x, queen=T, snap=T)
print("neighbours defined")
local <- spdep::localmoran(y, listw=nb2listw(neighbours, style="W"))
moran_map <- x
[email protected] <- cbind([email protected], local)
if(map.title = NULL) {
seg_map <- tmap::tm_shape(moran_map) +
tm_fill(col = "Ii",
style = "quantile",
title = "Local Moran's I Statistic") +
tm_layout(title = "Good Maps Have Titles")
return(map)
} else {
seg_map <- tmap::tm_shape(moran_map) +
tm_fill(col = 'Ii',
style = 'quantile',
title = "Local Moran's I Statistic",
palette = a) +
tm_layout(title = map.title)
return(map)
}
}
다음 오류가 계속 발생합니다.
>Error: no function to return from, jumping to top level
> }
Error: unexpected '}' in " }"
> }
Error: unexpected '}' in " }"
누구나 내가 뭘 잘못하고 있는지 어떻게 알 수 있습니까?
감사합니다. 당신이 그 오류를 가지고 전에
R :'map.title = NULL'에서는 작동하지 않습니다. 'isnull()'을 사용하십시오. – Parfait
그리고 * map *은 어디 있습니까? 'return (seg_map)'을 사용하십시오. – Parfait