Replies: 2 comments 1 reply
-
Yeah, I think The trickiest part is the serialization of non-exportable objects. Those Python pointers are not valid outside the current R session, and this could interfere with distributed computing scenarios. One workaround might be to define a project-level |
Beta Was this translation helpful? Give feedback.
-
I was able to use a python function via E.g. something like library(targets)
library(tarchetypes)
library(reticulate)
tar_plan(
tar_target(zeroes, make_zeroes())
) |> tar_hook_before(hook = source_python("py/test.py"), names = "zeroes")
Not super ideal, but if you only have a few targets that use python functions this seems to work, but doesn't track changes to the python script. |
Beta Was this translation helpful? Give feedback.
-
I am really excited about the
targets
package and love the functional style. Because R'sreticulate
package makes it so easy to include python functions in R and it handles all the conversion automatically, it got me thinking how we could use python scripts intargets
. I am sure the interest will be there, but I want to make sure the design principles are correct before I jump in and potentially build something for thetargetopia
. Or maybe you have also already though about this and have other plans.Here is the state of what is currently possible with python in targets:
Say we have a python file
py/test.py
with the following content:We can load all python scripts in our
_targets.R
file, inspired by the template of @MilesMcBain intflow
(https://github.com/MilesMcBain/tflow), via:However, because the reticulated python function looks the same to
targets
even if the underlying implementation ofmake_zeros
changes (i.e.<function make_zeros at 0x7f11df131430>
), we need to telltargets
to explicitly watch the source file for changes and mention it in the target:I would love input from
reticulate
experts on whether it is possible fortargets
to be able to track the reticulated functions as it does for R functions. And if this is not the case, if it would be a sufficient usecase for atargetopia
package to bundle the source-file-watching and function call into a target factory.Beta Was this translation helpful? Give feedback.
All reactions