Menu Home

My recent BARUG talk: Parametric Programming in R with replyr

I want to share an edited screencast of my rehearsal for my recent San Francisco Bay Area R Users Group talk:

Categories: Administrativia

Tagged as:

jmount

Data Scientist and trainer at Win Vector LLC. One of the authors of Practical Data Science with R.

5 replies

  1. To make “let” easier to import I have moved it to a new low-dependency package: wrapr. Newer reply will re-export “let” so all the examples should continue to work. Please see here for some details.

  2. Great stuff. You can eliminate the temporary column name in your lazyeval::interp example, though it requires nesting: d %>% mutate_(.dots = stats::setNames(lazyeval::interp(~ is.na(VAR), VAR = as.name(cname)), rname))

    1. Thanks, I appreciate the support and the info.

      I tried it in the source of vignette('ParametricExample', package= 'replyr'), and for me that sets the result column to “is.na(x)” (an improvement), not exactly to “x_isNA” (my goal in that vignette). My packageVersion('lazyeval') is 0.2.0 (current CRAN version as of Feb 28, 2017).

      
      library("dplyr")
      d <- data.frame(x= c(1,NA))
      cname <- 'x'
      rname <- paste(cname, 'isNA', sep= '_')
      print(rname)
      
       # [1] "x_isNA"
      
      d <- d %>% 
        mutate_(.dots = stats::setNames(
          lazyeval::interp(~ is.na(VAR), 
                           VAR = as.name(cname)), rname))
      print(d)
      
       # x is.na(x)
       # 1  1    FALSE
       # 2 NA     TRUE
      
  3. Oops I forgot you should surround the interp() call with list().

    library("dplyr")
    d <- data.frame(x= c(1,NA))
    cname <- 'x'
    rname <- paste(cname, 'isNA', sep= '_')
    print(rname)
    
     # [1] "x_isNA"
    
    d %>%
      mutate_(.dots = stats::setNames(list(
        lazyeval::interp(~ is.na(VAR),
                         VAR = as.name(cname))), rname))
     # x x_isNA
     # 1  1  FALSE
     # 2 NA   TRUE
    
    1. Walter, Thanks for taking the time to work this out! I learned something here. I’ve update the matching vignette to remove all uses of rename_().

%d bloggers like this: