Set object class to "psa" Determine sub-classes based on structure of files in the directory; there are two sub-classes assigned....one for the measurement method and one for the pre-treatment method. This makes the psa class easily extensible with new methods as I develop them! The only thing that must stay constant is the output of the method, and actually this doesn't really NEED to stay constant but it will make it much much easier when analyzing actual data to compare the methods. For example, I can always return the same 4-item list:
I have decided against using classes and object-oriented programming because it is not really meant for working with data frames. Instead I am going to use the
switch()
function which still allows this function to be extensible via new
helper functions as the PSA methods (in the physical sense) are created.
Some pseudocode:
across()
or something similar, perhaps based on the column positions. lag()
.....probably can do that for the above problem too, instead of messing with pivoting wider and then re-pivoting longer again. IT WORKS
Later at night, thought of a way to deal with the variable number of pipette samples...start with percent passing tibble, pivot wider across all column names having only digits....then conditionally mutate the table based on the protocol number and switch()
to compute the extra size classes only for the protocols that measure them. Actually what would be even better is to make this strucure no matter what but to input NA values if that bin was not measurable.
For now, I am going to only compute the columns gravel, sand, silt and clay as the default action....then if the protocol includes any extra size classes, I can append the table based on the detected protocol ID. This flows with the 'start simple but leave room for extension' philosophy of the psa functions.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.