Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backticks in variable name

Tags:

syntax

r

If I create a variable with a backtick in the name, is there a way to access it using the backtick syntax?

assign("a`b", 5)
get("a`b")
#[1] 5

# The attempts below all end in various errors
# `a`b`
# `a``b`
# `a\\`b`
like image 610
eddi Avatar asked Oct 03 '13 21:10

eddi


People also ask

What is the backtick character?

Alternatively known as acute, backtick, left quote, or an open quote, the back quote or backquote is a punctuation mark (`). It's on the same U.S. computer keyboard key as the tilde.

What do backticks mean in R?

backticks are used to indicate that the text between the backticks should be executed as a command. '['(women, 1:5, 1) "["(women, 1:5, 1) Copy [1] 58 59 60 61 62 [1] 58 59 60 61 62. It also turns out that ( is a function as well, which was what I surmised in my previous post.

How do you add a backtick in R?

As a bonus, you can also set the functions of an Addin to custom keyboard shortcuts and quickly access them from the RStudio command palette (just hit Shift + Cmd + P , or Shift + Ctrl + P , then type the word 'backtick').

Can variable name start with Dollar in C?

Output. According to this resource, it says that you can't start variable names with $ in C, which is wrong (at least when compiled using my gcc version, Apple LLVM version 10.0. 1 (clang-1001.0. 46.4)).


1 Answers

All your attempts end in various errors because ?Quotes says that you can only escape the characters listed in the (included) table; and "`" is not in that table.

You could use the hex, octal, etc. representation of "`" though:

> `a\x60b`  # hex
[1] 5
> `a\140b`  # octal
[1] 5
like image 63
Joshua Ulrich Avatar answered Sep 21 '22 18:09

Joshua Ulrich