Comments (4)
I'm not sure whether this is applicable to R, but the way this is usually approached in object-orientated languages is to contain all of the parameterisation in a configuration object.
An object has data and behaviours. When you create/modify the configuration object you can perform additional behaviours like checking that the parameterisation you are storing is valid. If, for example, you stored image_size then the object would check that sizes were positive (in addition to being type integer).
> my_config = Config(image_size=[800, 600]) # some settings can be added when the object is instantiated
> my_config.image_size = [-800, -600] # or added/changed later
Error - image dimensions must be positive # the object takes care of validation
Within your R code you can then use additional methods that are defined by the class for all config objects, e.g. you could store image_size in cm but have a method that returned the size in inches. This prevents the need to repeat the conversion logic in multiple functions, or having the logic just sitting in a stand-alone function somewhere.
Given my_config
and the need to parameterise ggplot2 you could have a method like .ggplot2_parameters
that returns the parameters required by ggplot2.
from cdms.products.
Thanks Ian, this has helped with our thinking on this.
This kind of approach makes a lot of sense in line with how ggplot2 works where individual components can be defined, stored and added on. I had initially thought we needed a different approach since we are going through Python wrappers, but I think we can maintain this separation still.
This idea is particularly relevant for themes, which controls the look of the non-data components of the graph e.g.
# base graph
p1 <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
labs(title = "Fuel economy declines as weight increases")
p1
# add theme options to base graph
p1 + theme(plot.title = element_text(size = 10))
So it makes sense not to implement themes within our own functions for the reasons you mentioned and as they may be used across functions.
The functions in this package can therefore stay relatively simple e.g.:
g <- inventory_plot(data = dodoma, date = "date", elements = "rain", year = "year", doy = "doy_366")
Theme options could be specified in the Python wrapper, with a Python implementation of the theme options (which is essentially just a list of lists). Then the Python wrapper can make an R call such as:
g <- inventory_plot(data = dodoma, date = "date", elements = "rain", year = "year", doy = "doy_366")
g + theme(legend.text = element_text(size = 8, colour = "red"))
from cdms.products.
@dannyparsons
For the example above, I assume that:
- the web component shall pass a list of themes to the Python wrapper function
- the theme may be encapsulated in an object
- the theme object may contain validity checks
- the wrapper function shall apply each theme to the ggplot object in order
- the wrapper function shall generate R calls similar to:
g <- inventory_plot(data = dodoma, date = "date", elements = "rain", year = "year", doy = "doy_366")
g + theme(legend.text = element_text(size = 8, colour = "red"))
g + theme(somethingElse.text = element_text(size = 10, colour = "blue"))
:
Did I understand correctly?
Thanks
from cdms.products.
Thanks Stephen. Yes, this is broadly in line with my thinking. The slight difference is that I expect there to be a single theme object in Python which will be applied as follows:
g <- inventory_plot(data = dodoma, date = "date", elements = "rain", year = "year", doy = "doy_366")
g + theme(legend.text = element_text(size = 8, colour = "red"),
somethingElse.text = element_text(size = 10, colour = "blue"))
All theme options can be done in a single theme function in R, but the general outline you give is the same, just a different R notation.
from cdms.products.
Related Issues (20)
- Creates extremes function
- Refer to `naflex` package on CRAN HOT 1
- Add an example dataset to the package
- Parameter names - consistency HOT 5
- Export CDT Dekadal data HOT 6
- Package name HOT 3
- Only use names and function signatures that are also valid in Python HOT 8
- Discussion on using "tidy evaluation" or not for column names HOT 2
- The signature of `export_geoclim_month` is inconsistent with Python
- Bugs in the inventory_plot function HOT 1
- Make tests accessible on installed package HOT 3
- Bug when using elements in the climatic_summary function HOT 2
- Add test for climatic_summary when there's no summaries provided
- Errors in prepare_geoclim function HOT 2
- Add test for climatic_summary that contains a `summaries_params` parameter HOT 3
- "element" not recognized in Input (file_path = paste0("CDT-", element, ".csv")
- Incorrect column names from export_geoclim_month.R
- R functions to write tests on HOT 4
- Parameters ignored in `export_geoclim_dekad()` and `export_geoclim_pentad()` HOT 1
- Invalid tests in `test-histogram_plot.R`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cdms.products.