-
Notifications
You must be signed in to change notification settings - Fork 75
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
tar_cue() change argument similar to change in drake::trigger() #130
Comments
The |
I thought about that last night and almost didn't file the feature request but I couldn't quite figure it out. I thought to make a target that always checked the database time. But I wasn't sure how to get a downstream target to depend on it. I built the following pipeline.
I'm not sure how
or am I missing something very obvious? |
The key is to force # _targets.R
library(targets)
tar_options(packages = c("DBI"))
read_db <- function(database_update_time) {
con <- DBI::dbConnect()
on.exit(close(con))
dbReadTable(con, 'mytable')
}
tar_pipeline(
tar_target(
database_update_time,
somehow_get_db_timestamp(),
cue=tar_cue(mode='always')
),
tar_target(
read_data,
read_db(database_update_time)
)
) # _targets.R
library(targets)
tar_options(packages = c("DBI"))
read_db <- function(database_update_time) {
con <- DBI::dbConnect()
on.exit(close(con))
dbReadTable(con, 'mytable')
}
database_update_time <- somehow_get_db_timestamp(),
tar_pipeline(
tar_target(
read_data,
read_db(database_update_time)
)
) I put the code in a custom |
Thanks for the info. I had a feeling I would need to write a function that wrapped
This is different than how I was using |
Yes, a target's command can be an arbitrary code chunk. I just find functions cleaner and clearer in most situations. # _targets.R
library(targets)
tar_options(packages = c("DBI"))
database_update_time <- somehow_get_db_timestamp()
tar_pipeline(
tar_target(
read_data, {
database_update_time # Mention the symbol to enforce the dependency relationship.
con <- DBI::dbConnect()
on.exit(close(con))
dbReadTable(con, 'mytable')
})
)
Yes, exactly. A non-exportable object such as a connection object should be defined as part of the command of the target that needs it. |
Cool. Thanks for the info. This tackles this problem for me. |
As I alluded to in #131, I think we can address your original request externally with ropensci/tarchetypes#2. |
Okay this is cool. So you can use |
Prework
targets
' code of conduct.targets
' contributing guidelines.Proposal
While it seems like dynamic files makes it easy to trigger targets when a file on disc changes, there does not seem to be a way to do the same for when a database table changes, at least as far as I can tell.
Per Chapter 4 of the
{drake}
book I would do something essentially like this.I would imagine something similar to the
change
argument could be added totar_cue()
. According to my preliminary reading of the help file,tar_cue()
only haslogical
arguments and nowhere to evaluate code such assomehow_get_db_timestamp()
.I suppose we could change the value passed tomode
based on an earlier target, but haven't tested that.The text was updated successfully, but these errors were encountered: