inst/tinytest/test_lhs_eval.R

test_lhs_eval_ad_hoc <- function() {
  # without the .() notation (not quiet what we want from the user)
  d <- data.frame(x = 1)
  ops <- local_td(d)
  for(i in 1:3) {
    ops <- extend(ops, paste0("v_", i) %:=% (i+1))
  }

  invisible(NULL)
}

test_lhs_eval_ad_hoc()

test_lhs_eval_b <- function() {
  # with the .() notation (the strict form)
  d <- data.frame(x = 1)
  ops <- local_td(d)
  for(i in 1:3) {
    ops <- extend(ops, .(paste0("v_", i)) %:=% (i+1))
  }

  invisible(NULL)
}

test_lhs_eval_b()


test_lhs_eval_b2 <- function() {
  # with the .() notation (the strict form)
  d <- data.frame(x = 1)
  ops <- local_td(d)
  for(i in 1:3) {
    v_i <- paste0("v_", i)
    ops <- extend(ops, .(v_i) %:=% (i+1))
  }

  invisible(NULL)
}

test_lhs_eval_b2()


test_lhs_eval_b2b <- function() {
  # with the .() notation (the strict form)
  d <- data.frame(x = 1)
  var <- 'y'
  # should be var
  ops1 <- local_td(d) %.>%
    extend(., var := 1)
  expect_true(length(grep('y', format(ops1)))==0)
  expect_true(length(grep('var', format(ops1)))==1)
  # should be y
  ops2 <- local_td(d) %.>%
    extend(., .(var) := 1)
  expect_true(length(grep('var', format(ops2)))==0)
  expect_true(length(grep('y', format(ops2)))==1)
  invisible(NULL)
}

test_lhs_eval_b2b()

Try the rquery package in your browser

Any scripts or data that you put into this service are public.

rquery documentation built on Aug. 20, 2023, 9:06 a.m.