jwdink / eyetrackingR

This package is designed to make dealing with eye-tracking data easier. It addresses tasks along the pipeline from raw data to analysis and visualization.
http://eyetrackingr.com
Other
82 stars 20 forks source link

Improve documentation for mutate_ and/or fix mutate_ #60

Closed respatte closed 6 years ago

respatte commented 6 years ago

Hi,

I'm trying to use the eyetrackingR friendly mutate_ to create new variables based on existing ones. The issue is that either (a) I use the variable name as I would usually with dplyr::mutate, but I get an error:

LT_data <- LT.data %>%
  mutate_(Part = case_when(TrialId %in% c("1","2","3","4","5","6","7","8") ~ 0,
                           TrialId %in% c("9","10","11","12","13","14","15","16") ~ 1,
                           TrialId %in% c("17","18","19","20","21","22","23","24") ~ 2)))
## Error in TrialId %in% c("1", "2", "3", "4", "5", "6", "7", "8") : 
##   object 'TrialId' not found

or (b) I use the . to access directly .$TrialId, and instead of the desired behaviour (give a value for Part to each row based on the value of TrialId for that row), R considers only the first value of TrialId:

LT_data <- LT.data %>%
  mutate_(Part = case_when(.$TrialId %in% c("1","2","3","4","5","6","7","8") ~ 0,
                           .$TrialId %in% c("9","10","11","12","13","14","15","16") ~ 1,
                           .$TrialId %in% c("17","18","19","20","21","22","23","24") ~ 2)))
## Warning message:
## Truncating vector to length 1

I looked at the help for mutate_, and therefore tried to use the .dots argument, checking the syntax from source code here, trying to use both TrialId directly or .$TrialId (just using .dots = list(Part = ...)).

I didn't manage to find out where in the source code mutate_ was implemented, the only thing I found was a one line definition in dplyr_fix.R that I couldn't really understand, and therefore I can't really work out how to use mutate_ properly. Could it be possible to write some documentation for it, or possibly make it work a bit more like the original dplyr::mutate function?

I forgot to say, the mutate_ help also says to check vignette("nse") for further indications on non-standard evaluation, but R doesn't find this vignette:

vignette("nse")
## Warning message:
## vignette ‘nse’ not found 

Thanks a lot

respatte commented 6 years ago

Just updated my R packages (including eyetrackingR) for an error with another package, and turns out mutate_ has now disappeared... And instead eyetrackingR works fine with dplyr::mutate!

That's quite amazing, thanks a lot for this update!