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

Bug Fixes #26

Merged
merged 6 commits into from
Apr 27, 2024
Merged

Bug Fixes #26

merged 6 commits into from
Apr 27, 2024

Conversation

smthfrmn
Copy link
Collaborator

@smthfrmn smthfrmn commented Apr 26, 2024

This PR does some refactoring and bug fixes, namely:

@nilanjanchatterjee I included comments throughout the code explaining what I did

{abline(v= dat_outp$V5, lty=2, lwd=1.5, col= "green4")
abline(v= dat_outp$V6, lty=4, lwd=1.5, col= "royalblue")
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move plotting functions outside of main function to make main function more readable


rFunction <- function(data, threshold = NULL, window = 72, yaxs_limit = 1000) {
original_track_id_column <- mt_track_id_column(data)
track_attribute_data <- mt_track_data(data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save track attribute data for returning object at the end

)

if (nrow(track_data) > 10 & tint > window) { ## To filter individuals with very few relocations
data_temp <- tryCatch(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing all this in one dplyr function

)
),
error = function(e) {
if (grepl("rollmean", e$message)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch error that can happen if window is too small

for (i in 1:length(track_ids)) {
track_id <- track_ids[i]

animal_id <- track_attribute_data |>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting animal id

))

# convert the data.frame output into move2 object
dat_final <- left_join(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join track attribute data back with data from function

@@ -0,0 +1,39 @@
source(here("tests/testthat/helper.R"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some unit tests to make sure function executes

@nilanjanchatterjee
Copy link
Owner

Gone through the changes you have made and most of them make sense to me...I'll do some more through testing probably with some edge cases...Great work @smthfrmn

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