ameztegui / Plasticity

An R package to compute several plasticity indices
MIT License
3 stars 2 forks source link

Raw values not saving #2

Closed Dudududy closed 7 months ago

Dudududy commented 7 months ago

Hello!

I am currently working with the Plasticity package, but I am facing some issues with saving my raw values from the rdpi command - more specifically, I cannot get the verbose argument to work.

In my dataset I got two species (Hmo and Hpe), but for some traits, the amount of measurements are too low for Hmo for rdpi to be calculated (in my case across origin populations). I am okay with not having a value for the Hmo species, but the problem now is, that I can't get it to save the raw values for the species Hpe that should be fine?

image

In my code, I am trying to save the raw values by:

rdpi_height <- rdpi (df, sp = Species, trait =plant_height, factor = origin, verbose = T)

I get the boxplot produced, but it does not save anything under "rdpi_height" in my global environment, as states: unused argument (verbose = T).

In other traits, when values are sufficient for both Hmo and Hpe, everything works fine.

Do you know how I can work around this problem or why verbose doesn't seem to be working?

Cheers!

ameztegui commented 7 months ago

Thanks for your comment, The verbose argument is no longer used in the rdpi() function, that's why you get the error. You should remove it from your function. The behavior of saving or not the values is controlled by whether you assign the function to an object or not. So rdpi (df, sp = Species, trait =plant_height, factor = origin) would plot the chart but would not save the values, whereas rdpi_height <- rdpi (df, sp = Species, trait =plant_height, factor = origin) would also save the values to the rdpi_height object, Please try and let me know if it works.

That said, it is really weird that you actually get the boxplot despite the error message. To be honest, I cannot explain this.

Best regards

Dudududy commented 7 months ago

Thanks for your quick reply!

The normal assignment of a function to an object doesn't work when I get the error message:

It still produces the boxplot and performs the analysis, but no object gets saved, even if I use: rdpi_height <- rdpi (df, sp = Species, trait =plant_height, factor = origin)

However, this works as intended when I run the same code with a different dataset (for a different site, where I got enough measurements for both species).

I have been trying to think around this problem of the error, and if I could continue to calculate the rdpi just for the one species where I do have sufficient data, but then I get a grouping factor error: "Error in t.test.formula(RDPI$rdpi ~ RDPI$sp) : grouping factor must have exactly 2 levels", as I now only would have 1 level for my species.

image

Again, the boxplot is produced despite the error, but the object (rdpi_height) does not get saved.

I am confused as to why it doesn't want to save whatever raw values has been calculated for the Hpe species - maybe it clashes with something in the rdpi function?

ameztegui commented 7 months ago

Mmm, I see... That is weird indeed. I mean, it's normal that you don't get the output of the t-test, but why shouldn't you get the values? Would you mind sending me a small example of your dataset so I can go step by step and see where the problem comes from? Thank you!

Dudududy commented 7 months ago

Yes, here is a small subset of the full dataset. HEL is the df where there seems to be enough measurements for both traits (LengthLongestBranch and NumbLeafPairs) for the rdpi to run as intended. For SUS there are many NAs, especially for the Hmo species, and here I cannot save the values to an object.

I ran the code:

rdpi_LLB <- rdpi (df, sp = Species, trait = LengthLongestBranch, factor = Origin)

HEL.csv SUS.csv

Thank you very much for taking your time to look at it!

ameztegui commented 7 months ago

Ok, I think I got it. When trying to perform the t-test, it obviously produced an error, which made the function stop. Now it first assesses if the t-test can actually be done, and else it returns the message "To compute a t-test the grouping factor must have exactly 2 levels", but continues to perform the rest of calculations.

Please download the new version from Github and let me know if it works.

best regards

Aitor

Dudududy commented 7 months ago

Amazing! I just tried it out and the raw values are getting saved and everything seems to be working now!

Thank you so much!