Skip to content
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

Add some functionality for exporting data as simple .csv files #50

Open
andrew-edwards opened this issue Feb 24, 2024 · 3 comments
Open
Assignees

Comments

@andrew-edwards
Copy link
Member

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.

@andrew-edwards andrew-edwards self-assigned this Feb 24, 2024
@andrew-edwards
Copy link
Member Author

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.

@cgrandin
Copy link
Contributor

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.

@andrew-edwards
Copy link
Member Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants