cells2numbers / migrationminer

MigrationmineR is a R package to analyse and profile in vitro cell tracking and migration data. It is belongs to the cytominer-verse used for morphological profiling and allows to create temporal or dynamic profiles.
Other
5 stars 0 forks source link

#2 added variable names for x, y and time coordinate and tidyeval #14

Closed cells2numbers closed 5 years ago

cells2numbers commented 6 years ago

First function was rewritten with colnames of x, y and time coordinates as input.

Basically, the old code

  dplyr::mutate(Track_dX = Location_Center_X.x - Location_Center_X.y) %>%
  dplyr::mutate(Track_dY = Location_Center_Y.x - Location_Center_Y.y) %>%
  dplyr::select(-Location_Center_X.x, -Location_Center_Y.x) %>%
  dplyr::rename(Location_Center_X = Location_Center_X.y) %>%
  dplyr::rename(Location_Center_Y = Location_Center_Y.y) %>%
  dplyr::rename(Metadata_timePoint = Metadata_timePoint2) %>%

becomes

 dplyr::mutate(
    Track_dX =
      (!!(as.name(stringr::str_c(x_var, ".x")))) -
      (!!(as.name(stringr::str_c(x_var, ".y"))))
  ) %>%
  dplyr::mutate(
    Track_dY =
      (!!(as.name(stringr::str_c(y_var, ".x")))) -
      (!!(as.name(stringr::str_c(y_var, ".y"))))
  ) %>%
  dplyr::select(
    - (!!(as.name(stringr::str_c(x_var, ".x")))),
    - (!!(as.name(stringr::str_c(y_var, ".x"))))
  ) %>%
    #
    # when using rename with expression "=" needs to be replaced with ":=", see
    # https://github.com/tidyverse/dplyr/issues/1600
    # also see vignette("programming")
  dplyr::rename(
    !!x_var := !!stringr::str_c(x_var, ".y")
  ) %>%
  dplyr::rename(
    !!y_var := !!stringr::str_c(y_var, ".y")
  ) %>%

ToDo: look for a better solution to calculate the displacement. Better = without the need of the helper column!

Helpful sources: https://github.com/tidyverse/dplyr/issues/1600, also see vignette("programming")

Functions that need to be updated:

Some good resources for tidy eval: https://maraaverick.rbind.io/2017/08/tidyeval-resource-roundup/

codecov[bot] commented 6 years ago

Codecov Report

Merging #14 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #14   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines         144    173   +29     
=====================================
+ Hits          144    173   +29
Impacted Files Coverage Δ
R/track.R 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3b0ab70...4c0c1a8. Read the comment docs.