I have the following code, where the filtering of geo
is one line lower then the filter()
command itself. If the pype is run with ctrl+enter with cursor anywhere before the filter ends, the code runs properly, but if the cursor is behind filter()
(say somewhere on spread()
), an error appears:
Error in UseMethod("spread_") : no applicable method for 'spread_' applied to an object of class "function"
I did not expect, that the position where the cursor is set, defines if the pype results in error or not, which appears only if the the first filter argument is lowered by one line. If the code is filter(geo...
the cursor position does not matter. Does anybody have a suggestion why such behavior appears?
code:
library(eurostat)
library(dplyr)
library(tidyr)
earn_mw_avgr2 <- get_eurostat("earn_mw_avgr2", stringsAsFactors = FALSE)
df <- earn_mw_avgr2 %>%
filter(
geo %in% c("BE","BG","CZ","DK","DE","EE","IE","EL","ES","FR","HR",
"IT","CY","LV","LU","HU","MT","NL","AT","PL","PT","RO",
"SI","SK","FI","SE","UK"),
indic_se=="MW_MEAGE",
nace_r2=="B-S") %>%
spread(time, values)%>%
select(-c(17,18))%>%
mutate(avg=rowMeans(.[14:16], na.rm = TRUE))%>%
arrange(desc(avg))