Skip to content

Instantly share code, notes, and snippets.

@y9c
Created April 7, 2020 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y9c/c43fd601f2ab41f80f05462178f1192e to your computer and use it in GitHub Desktop.
Save y9c/c43fd601f2ab41f80f05462178f1192e to your computer and use it in GitHub Desktop.
Quasiquotation of R is terrible.
#!/usr/bin/env Rscript
# -*- coding: utf-8 -*-
#
# Copyright © 2020 Ye Chang <yech1990@gmail.com>
# Distributed under terms of the MIT license.
#
# Created: 2020-04-07 14:27
f <- function(x) {
print(x)
}
rev_f <- function(x) {
if (is.name(substitute(x))) {
print(as.character(substitute(x)))
} else {
print(eval(as.name(x), envir = .GlobalEnv))
}
}
x <- "hello"
f(x)
f("x")
rev_f(x)
rev_f("x")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment