apply_tracks: Run function on each track in a psyo data frame

Description Usage Arguments Value Credit Warning Author(s) See Also Examples

View source: R/apply_tracks.R

Description

Run function on each track in a psyo data frame. The function is in form of a character expression.

Usage

1
2
3
4
apply_tracks(tracks, exp,
  arg1 = "", arg2 = "", arg3 = "", arg4 = "",arg5 = "", arg6 = "", arg7 = "",
  arg8 = "", arg9 = "", t_id = "id", info = FALSE
)

Arguments

tracks

psyo. Data frame containing tracks in psyo format.

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 t_id = "" to make no selection but take all data.

info

logical. Measures the time consumption for each track calculation.

Value

psyo

Credit

If you use 'psyosphere' for commercial use or research, please support us by include one off the following references:

Warning

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.

Author(s)

Benjamin Ziepert

See Also

psyo, apply_shift

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
## Not run: 
# 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 <- apply_tracks(
  psyo,"test_sum(eval_track)"
)

# See all data as one track
data(psyo)
psyo <- apply_tracks(
  psyo,"test_sum(eval_track)", t_id =""
)

# Use of arguments
data(psyo)
psyo <- 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 <- apply_tracks(
  psyo,"test_wrong(eval_track, arg1)", arg1 = psyo
)


## End(Not run)

psyosphere documentation built on July 2, 2020, 12:08 a.m.