1 view

In the following code, I want to print the output of fn(a = b) as:

"a = b" and fn(a = gn(b), 3~b~a, dd, e = 2 + f, h = hn(jn(cdf))) to be list("a=gn(b)", "3~b~a", "dd", "e=2+f", "h= hn(jn(cdf)))"

fn = function(...) {

# print the content of ... without evaluation?

}

fn = function(...) {

res = rlang::enexprs(...)

paste0(names(res), ifelse(names(res)=="",names(res) , "=") , sapply(res, capture.output))

}

by (108k points)

For achieving that you can simply use match.call() :

fn = function(...) {

temp <- as.list(match.call())[-1]

as.list(sub('^=', '', paste0(names(temp), '=', temp)))

}

fn(a = b)

#[]

# "a=b"

fn(a = gn(b), 3~b~a, dd, e = 2 + f, h = hn(jn(cdf)))

#[]

# "a=gn(b)"

#[]

# "3 ~ b ~ a"

#[]

# "dd"

#[]

# "e=2 + f"

#[]

# "h=hn(jn(cdf))"

If you are a beginner and want to know more about R then do check out the R programming course
{"ft_lang_label":"__label__en","ft_lang_prob":0.64902395,"math_prob":0.9996737,"size":432,"snap":"2022-27-2022-33","text_gpt3_token_len":152,"char_repetition_ratio":0.10747664,"word_repetition_ratio":0.0,"special_character_ratio":0.43287036,"punctuation_ratio":0.28318584,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99968064,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-25T02:21:49Z\",\"WARC-Record-ID\":\"<urn:uuid:9739452b-0a92-47ee-830f-9555dd538810>\",\"Content-Length\":\"85831\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:76159087-c838-43f6-93b7-126ea6f0b191>\",\"WARC-Concurrent-To\":\"<urn:uuid:6e4e1880-a50a-4472-88db-17d47f3b72a6>\",\"WARC-IP-Address\":\"104.18.27.176\",\"WARC-Target-URI\":\"https://intellipaat.com/community/48000/r-how-to-return-the-exact-form-of-in-fn-without-evaluating\",\"WARC-Payload-Digest\":\"sha1:A25TIGKOZZDSSHUPGYQ44SQMSHKPGPMW\",\"WARC-Block-Digest\":\"sha1:KAJGR25S2N6PIPOYPDISEEL2BJ6XDDHW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103033925.2_warc_CC-MAIN-20220625004242-20220625034242-00496.warc.gz\"}"}