R Flashcards

1
Q

How to view a function’s code?

A

Press F2 with cursor on a function, or use View(function)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What function is used to check if a name is appropriate/valid to assign to a new R package?

A

available::available(“my_package_name”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What tool is used to create documentation for the R package?

A

“Roxygen” - turn it on under Build - More - Configure Build Tools. To start, pur the curser on a function and go to Code - insert Roxygen skeleton.

Roxygen generate the .Rd file and the NAMESPACE file for you

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Open Source Licenses - Apache, MIT, GPL

A

GPL-2, GPL-3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is vignette in R

A

TBD

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What function is used to join a set of strings without adding space in between?

A

paste0(“my name is “, my_name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s the purpose of the NAMESPACE file in the package folder?

A

It outlines functions imported from other packages for users to be able to use, and functions you wrote available for people who loads the package to use
- export(function_name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are S3, S4 classes/methods in R?

A

In R, classes/methods are different from what it is in the traditional OOP sense. S3 and S4 in R are a way to implement ploymorphism for static functions. They are dispatching schemes.

  • S3 is the old-style, more informal and easier to implement (quick and dirty). S4 is newer, more rigorous.

Quote: “If you really need inheritance and more complicated polymorphism, you probably want to look into S4 classes and Reference and R6 classes. But only after you have understood the concept of environments and generic S3 functions. You might also want to reconsider whether Python isn’t the better language for your task.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the R object systems?

A

S3, S4, R6, RC aka “Reference Classes”

“S” refers to the S programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a class, an object, and a method in R?

A
  • A class is the thing itself (think of a list, a tibble).
  • An object is an instance of a class.
  • A method is a function that only operates on a certain class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s are generic functions? How are they related to the concept of classes in R?

A

Generic functions, such as “plot”, “mean”, “predict”, “print”, find out the class of the object it’s called upon and execute the method available under that class.

This is an application of its encapsulation because its ability to match methods with the object class is encapsulated within this generic function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to see the methods available of a S3 generic functions?

A

> methods(“mean”)
[1] mean,ANY-method mean,Matrix-method mean,sparseMatrix-method
[4] mean,sparseVector-method mean.Date mean.default
[7] mean.difftime mean.POSIXct mean.POSIXlt
[10] mean.quosure*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to see the methods available of a S4 generic functions?

A

> showMethods(“print”)

Function “print”:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are default methods for generic functions?

A

Usually generic functions have default methods, to be used when no other methods are found suitable.

For S3 methods (print), you can view the default code by:
> getS3method(“print”,”default”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Functional OOP vs Encapsulated OOP in R

A

In functional OOP, methods belong to generic functions. Think of the methods as being located in a global lookup table. The method to execute is found by the runtime system based on the name of the function and the type (or object class) of one or more arguments passed to that function (this is called “method dispatch”). Examples are S3, S4 object systems.

In Encapsulated OOP, method calls typically look like object.method(arg1, arg2). This is called encapsulated because the object encapsulates both data (fields) and behaviour (methods). Think of the method as being located in a lookup table attached to the object or the object’s class description. Examples are Reference Classes and R6.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are R6 classes/methods in R?

A

[EDIT NEEDED]

  • Encapsulated OOP approach.
  • Second most important system according to Hadley.
  • Not built-in with R; need to install the R6 library
  • Similar to RC, but lighter & much faster: it does not depend on S4 or the methods package.

Link to chapter in Advance R by Hadley: https://adv-r.hadley.nz/r6.html

17
Q

What are Reference Classes (RC) in R?

A

[EDIT NEEDED]

  • Encapsulated OOP approach.
  • Comes with base R.
  • Based on S4.
18
Q

Shiny app

A

Hhh