Comments (4)
I can jump in quite quickly on this one.
The short answer is: it's not possible and probably not desirable with S4.
The long answer is...
Some justification:
S4 addressing is designed for very defined data structures (which is why we chose it: the structure of the databases are very rigid). It's not possible to add slots unless we specify what class they're for, and there's no way of knowing what class the user would want to add. We could add something like 'list' and leave it empty, but it's definitely a fudge. We'd have to decide on the name of that slot, so the user wouldn't be able to call it what they want. That extra slot would give us one extra variable, but that's it: if we want more than one we'd also have to anticipate how many slots people may want, as it's not possible (or desirable) to add slots to a an S4 object ad hoc. An S4 object is designed to be inflexible: it really is the case that once you define the structure, that's it.
Options to do what you need:
- It is possible to add data to the metadata: saving the matrices as strings in extra metadata columns is a possibility, but I realise it's clunky when you're trying to work with the data, if you want to keep the new variable associated with the database all the time.
- This one may give you a satisfactory solution. The CompadreData and CompadreM classes are exported, so it's possible for a user to have access to these and define a new class of their own desired structure, which inherits from this/these classes, if they so wish. This would do exactly what you want, as you would get to define the new slots. It's easy to do. It wouldn't be a part of the package, though. We could include it in an "Advanced users" section in the vignette or examples, perhaps.
I get where you're coming from... the new structure will probably change the way I work with the data too. But for me, the benefits of locking in the structure of the databases for general use outweighs this.
If/when we get to functions that query and pull straight from the servers, having this locked-in structure will also be really helpful, I think.
from rcompadre.
The metadata
slot is an S3 data.frame so you can add whatever you want to that as long as we don't impose a dimension or column name check in the CompadreData
class definition. The main drawback here is that you can only add to the metadata
table, not actually create a new slot. But see #27 for some other (perhaps overly verbose) thoughts.
from rcompadre.
I somehow didn't realize that an S3 data.frame could have list-columns. I thought that was extra tibble magic, but I see now that it works just fine with data.frame too. So that basically solves all my problems.
Regardless, I like the idea of merging metadata
and mat
into a data
slot (#27), which makes adding additional list-columns for derived vectors/mats slightly more intuitive.
from rcompadre.
Adding derived columns is now straightforward thanks to @iainmstott's updates in #32 and #43, so closing this issue.
from rcompadre.
Related Issues (20)
- Add a function to output a Matlab compatible data file
- Function to load local com(p)adre .Rdata files HOT 3
- Change name of matrixClass to MatrixClass for consistency HOT 4
- Check that Rcompadre works well with the old database versions HOT 1
- Add method for droplevels
- Add function to create CompadreDB object from matrices and metadata. HOT 2
- Write vignette to illustrate `cdb_build_cdb` functionality HOT 1
- cdb_rbind - allow binding of COMPADRE objects with different metadata.
- mat_to_string fails when whole matrix is NA HOT 1
- filter error when compiling vignette. Error in storage.mode(x) <- "double" :
- Improve vignette to illustrate cdb_build_cdb functionality
- Add argument to cdb_fetch to automatically add error flag columns HOT 1
- Add vignette with NO piping HOT 1
- Add unit tests to cdb_build_cdb
- Standardize case convention on database column names HOT 1
- add methods for CompadreDB objects or supress helper text HOT 2
- suggestion for additional calculations across matrices: mat_sd and mat_median HOT 2
- 2 small taxonomic inconsistencies for crocodiles and turtles? HOT 1
- cdb_rbind improvement
- popbio should be popdemo HOT 1
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 rcompadre.