You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quick thought - should be able to write a function, say export_as_csv(), that detects the class of the pacea object, and then exports it in a suitable way.
Likely not really possible for the complex spatiotemporal results as can only really save data frames. Though could maybe add functionality to extract a specific month, and then there'd just be a data frame.
There's a built in way to do this in R. If your objects have different classes, then create one export function for each class type. Then you can call the generic one on any of them:
e.g.
"object" one has class "temporal"
export_csv.temporal <- function(object){
# Write the code to export the "temporal" class as a csv here
}
"object" two has class "data.frame"
export_csv.data.frame <- function(object){
# Write the code to export the "data.frame" class as a csv here
}
and so on ...
Then, for all classes with a function written for them in your project: export_csv(object)
and the correct function will be called automatically
Note that you need the dots in the function names (as shown) for this to work. This is why I never use dots in function names I write, you could inadvertently overwrite one of these hidden functions.
Thanks. Yes, the objects do have different classes already, and we have functions like plot.pacea_index() for exactly the reasons you said, but I somehow hadn't thought about applying this to other types of functions. Nice - so a few slightly different functions, rather than a larger one...
This would be useful for Matlab or Python users, especially if they can run short R scripts (or get someone to run a few commands quickly for them).
The spatio-temporal data/outputs would likely not be possible, but much of the rest should be.
@mjacox, @rebeccathomas-NOAA, and Stephane Gauthier would be interested.
The text was updated successfully, but these errors were encountered: