apply_tracks {psyosphere} | R Documentation |
Run function on each track in a psyo
data frame. The function is in form of a character expression.
apply_tracks(tracks, exp, arg1 = "", arg2 = "", arg3 = "", arg4 = "",arg5 = "", arg6 = "", arg7 = "", arg8 = "", arg9 = "", t_id = "id", info = FALSE )
tracks |
|
exp |
character. The function and arguments that will be evaluated. |
arg1 |
multiple. Arguments that will be sent to the target function. |
arg2 |
multiple. Arguments that will be sent to the target function. |
arg3 |
multiple. Arguments that will be sent to the target function. |
arg4 |
multiple. Arguments that will be sent to the target function. |
arg5 |
multiple. Arguments that will be sent to the target function. |
arg6 |
multiple. Arguments that will be sent to the target function. |
arg7 |
multiple. Arguments that will be sent to the target function. |
arg8 |
multiple. Arguments that will be sent to the target function. |
arg9 |
multiple. Arguments that will be sent to the target function. |
t_id |
Unique by time sorted ID for every coordinate within a track. Use |
info |
logical. Measures the time consumption for each track calculation. |
If you use Psyosphere for commercial use or research, please support us by include one off the following references:
Creative Commons: "Psyosphere" by B. Ziepert, E. G. Ufkes & P. W. de Vries from analyse-gps.com / CC-BY-SA-4.0
APA: de Vries, P. W., et al. (2016). "De psychologie van bewegingen GPS-technologie voor de analyse van natuurlijk gedrag." Tijdschrift voor Human Factors 2: 11-15.
Don't use this function for psyosphere main functions. Most of the psyosphere functions have apply_tracks()
already included. By adding it again you can get strange results or break the function.
Only return the changed "eval_track" as result. The function is splitting a psyo
data frame in sub tracks. After changes are applied that sub tracks or merged together again. Therefore, it is important to only work in the sub track. If for instance every time the psyo
data frame is returned by the evaluated function than the data frame gets stacked again and again on top of itself. See the examples below for how this can look like.
Benjamin Ziepert
# Working examples ------------------------------------------------------------- # Test function for examples test_sum <- function(track, more = 0) { track$lon_sum <- sum(track$lon) + more return(track) } # Simple example data(psyo) psyo <- psyosphere::apply_tracks( psyo,"test_sum(eval_track)" ) # See all data as one track data(psyo) psyo <- psyosphere::apply_tracks( psyo,"test_sum(eval_track)", t_id ="" ) # Use of arguments data(psyo) psyo <- psyosphere::apply_tracks( psyo,"test_sum(eval_track, arg1)", arg1 = 5 ) # What not to do --------------------------------------------------------------- # Only return the changed "eval_track" as result. The following examples show # what can go wrong otherwise. test_wrong <- function(selected_track, all_tracks) { all_tracks$sum <- all_tracks$lon + all_tracks$lat return(all_tracks) } data(psyo) psyo <- psyo[psyo[,c("p_id")]== 0,] psyo <- psyosphere::apply_tracks( psyo,"test_wrong(eval_track, arg1)", arg1 = psyo )