Exercise

Working with Environments (2)

Most types of R variable use "copy by value", meaning that when you take a copy of them, the new variable has its own copy of the values. In this case, changing one variable does not affect the other.

Environments use a different system, known as "copy by reference", so that all copies are identical; changing one copy changes all the copies.

Useful biology fact: RNA bases are slightly different to DNA bases. They are A, C, G, and U.

Instructions 1/2

undefined XP
  • 1
    • Make a copy of lst and assign it to lst2.
    • Change the 4th element of bases of lst to "U".
    • Test if the bases elements of lst and lst2 are the same, using identical(). Pass lst$bases as the first argument and lst2$bases as the second.
  • 2

    Do the same with environments. Notice the use of list2env() to convert a list to an environment.

    • Make a copy of env and assign it to env2.
    • Change the 4th element of bases of env to "U".
    • Test if the bases elements of env and env2 are the same, using identical().