Skip to content

Instantly share code, notes, and snippets.

@y9c
Created April 7, 2020 07:02
Show Gist options
  • 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 <[email protected]>
# 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