-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Directly modifying the data slot of S4 Spatial objects within functions confuses drake. #1130
Comments
Odd, I cannot reproduce the issue on either Mac OS or RHEL 7. Maybe you have an old cache somewhere in library(drake)
remotes:::local_sha("drake")
#> [1] "061d8d89ae98cafc8b6d1178d94da9ae2eebba79"
writeLines(
c(
" library(drake) ",
" library(sp) ",
" ",
" compute_area <- function(x) { ",
" ",
" ## Do not access slots like this! ",
" x@data$cadmium <- 1 ",
" ",
" ## These are the safe ways, and they work fine with drake ",
" # slot(x, 'data')$cadmium <- 1 ",
" # x$cadmium <- 1 ",
" ",
" ## Yet, the issue do not arise with other slots. ",
" ## For instance, the following modification works ",
" # x@bbox <- x@bbox + 1 ",
" ",
" return(x) ",
" } ",
" ",
" data(meuse) ",
" ",
" plan <- drake_plan( ",
" meuse_sp = SpatialPointsDataFrame( ",
" coords = meuse[, c('x', 'y')], ",
" data = meuse ",
" ), ",
" ",
" tgt = compute_area(meuse_sp) ",
" ) ",
" ",
" drake_config(plan) "
),
"_drake.R"
)
r_make()
#> �[32mtarget�[39m meuse_sp
#> �[32mtarget�[39m tgt
r_outdated()
#> character(0)
r_make()
#> All targets are already up to date. Created on 2020-01-09 by the reprex package (v0.3.0) |
After all morning and thanks to Docker, I've found the issue. If you want to check, I pushed a Docker image from the following Dockerfile:
You can easily reproduce in your browser if you have Docker installed:
Browse to
to reproduce. Since this is related with an outdated version of another package, I don't think any further action is required. Sorry about that. |
I never would have guessed, thanks for looking into it. The solution is surprising at first glance, but one of the news items of
So if we use library(drake)
packageVersion("callr")
#> [1] '3.3.0'
writeLines(
c(
" library(drake) ",
" library(sp) ",
" ",
" compute_area <- function(x) { ",
" ",
" ## Do not access slots like this! ",
" x@data$cadmium <- 1 ",
" ",
" ## These are the safe ways, and they work fine with drake ",
" # slot(x, 'data')$cadmium <- 1 ",
" # x$cadmium <- 1 ",
" ",
" ## Yet, the issue do not arise with other slots. ",
" ## For instance, the following modification works ",
" # x@bbox <- x@bbox + 1 ",
" ",
" return(x) ",
" } ",
" ",
" data(meuse) ",
" ",
" plan <- drake_plan( ",
" meuse_sp = SpatialPointsDataFrame( ",
" coords = meuse[, c('x', 'y')], ",
" data = meuse ",
" ), ",
" ",
" tgt = compute_area(meuse_sp) ",
" ) ",
" ",
" drake_config(plan) "
),
"_drake.R"
)
r_make()
#> �[32mtarget�[39m meuse_sp
#> �[32mtarget�[39m tgt
r_outdated()
#> [1] "tgt"
r_vis_drake_graph() r_make()
#> �[32mtarget�[39m tgt Created on 2020-01-10 by the reprex package (v0.3.0) So this is indeed a bug in |
Minimal reprex: drake::deps_code(quote(x@y))
#> # A tibble: 2 x 2
#> name type
#> <chr> <chr>
#> 1 x globals
#> 2 y globals Created on 2020-01-10 by the reprex package (v0.3.0) Expected result: #> # A tibble: 1 x 2
#> name type
#> <chr> <chr>
#> 1 x globals |
Incredible. What a creative way of breaking things :)))
Glad it helped. At least I didn't just spend a day and a half without a purpose :) |
You definitely made a contribution. Thanks for reporting! |
Prework
drake
's code of conduct.remotes::install_github("ropensci/drake")
) and mention the SHA-1 hash of the Git commit you install.Description
When you directly modify the
data
slot of a S4 Spatial object (from package {sp}) within a function,drake
does not update the target. Therefore, the target itself and all those that depend on it downstream remain outdated.I'm not sure whether this is a problem only with {sp} objects, or it is a more general issue with S4 objects and slots.
I'm aware that directly accessing a slot is bad practice. The solution is simple: use
slot()
or$
(see repr. example). I just wanted to leave this here for reference for others and in case you want to take a look at the underlying problem. It took me a while to narrow down the issue.Reproducible example
Created on 2020-01-09 by the reprex package (v0.3.0)
Expected result
Ideally,
r_outdated()
should yield nothing.drake
would execute the target and mark it as done.But taking into account that correctly accessing the
data
slot does not trigger the issue, this can be safely closed.Session info
Session info
The text was updated successfully, but these errors were encountered: