5

Can I (should I) use R attributes to save physical units and similar information as hint for the user?

epsilon0 <- 8.854188e-12
# name <- "electric constant"
# source <- "CODATA"
# unit <- "F m-1"
Jonas Stein
  • 6,826
  • 7
  • 40
  • 72

2 Answers2

5

You can, with this code:

attributes(epsilon0) <- list(name = "electric constant", source = "CODATA", unit="F m-1")
Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112
4

In addition to @MatthewLundberg's answer, you can set and get individual attributes like:

> attr(epsilon0,"name") <- "electric constant"
> epsilon0
[1] 8.854188e-12
attr(,"name")
[1] "electric constant"


> attr(epsilon0,"name")
[1] "electric constant"
thelatemail
  • 91,185
  • 12
  • 128
  • 188