daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. > system.time(x <- rnorm(10))
  2.    user  system elapsed
  3.       0       0       0
  4. > system.time(x = rnorm(10))
  5. Error in system.time(x = rnorm(10)) : unused argument(s) (x = rnorm(10))
  6.    
  7. `=` <- function(...) stop("Assignment by = disabled, use <- instead")
  8. # seems to work
  9. a = 1
  10. Error in a = 1 : Assignment by = disabled, use <- instead
  11. # appears not to break named arguments
  12. sum(1:2,na.rm=TRUE)
  13. [1] 3
  14.    
  15. temp <- tempfile()
  16. write("foo = function(...) {
  17.           good <- 0
  18.           bad = 1
  19.           sum(..., na.rm = TRUE)
  20.        }", file = temp)
  21.  
  22. library(lint)
  23. lint(file = temp, style = list(styles.assignment.noeq))
  24. # Lint checking: C:UsersflodelAppDataLocalTempRtmpwF3pZ6file19ac3b66b81
  25. # Lint: Equal sign assignemnts: found on lines 1, 3
  26.    
  27. `=` <- function(...){
  28.         .what <- as.list(match.call())
  29.         .call <-  sprintf('%s <- %s', deparse(.what[[2]]),  deparse(.what[[3]]))
  30.         mess <- 'Use <- instead of = for assigment '
  31.         if(getOption('warn_assign', default = T)) {
  32.         stop (mess) } else {
  33.         warning(mess)
  34.         eval(parse(text =.call), envir = parent.frame())  
  35.           }
  36.         }
  37.    
  38. # with no option set
  39. z = 1
  40. ## Error in z = 1 : Use <- instead of = for assigment
  41. options(warn_assign = T)
  42. z = 1
  43. ## Error in z = 1 : Use <- instead of = for assigment
  44.  options(warn_assign = F)
  45.  z = 1
  46. ## Warning message:
  47. ##  In z = 1 : Use <- instead of = for assigment
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top