Learn R Programming

PaRe (version 0.1.16)

Function: R6 Function class.

Description

Class representing a function.

Arguments

Super class

PaRe::Code -> Function

Methods

Inherited methods


Method new()

Initializer for Function object.

Usage

Function$new(name, lineStart, lineEnd, lines)

Arguments

name

(character)
Name of Function.

lineStart

(numeric)
Line number where function starts in File.

lineEnd

(numeric)
Line number where function ends in File.

lines

(c)
Vector of type character Lines of just the function in File.

Returns

invisible(self)


Method getFunction()

Get method to get defined functions in a File object.

Usage

Function$getFunction()

Returns

(data.frame)

columndata type
name(character)
lineStart(integer)
lineEnd(numeric)
nArgs(integer)
cycloComp(integer)


Method clone()

The objects of this class are cloneable with this method.

Usage

Function$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

See Also

Other Representations: Code, File, Repository

Examples

Run this code
fetchedRepo <- tryCatch(
  {
    # Set dir to clone repository to.
    tempDir <- tempdir()
    pathToRepo <- file.path(tempDir, "glue")

    # Clone repo
    git2r::clone(
      url = "https://github.com/tidyverse/glue.git",
      local_path = pathToRepo
    )

    # Create instance of Repository object.
    repo <- PaRe::Repository$new(path = pathToRepo)

    # Set fetchedRepo to TRUE if all goes well.
    TRUE
  },
  error = function(e) {
    # Set fetchedRepo to FALSE if an error is encountered.
    FALSE
  },
  warning = function(w) {
    # Set fetchedRepo to FALSE if a warning is encountered.
    FALSE
  }
)

if (fetchedRepo) {
  files <- repo$getRFiles()
  file <- files[[1]]
  funs <- file$getFunctions()
  funs[[1]]
}

Run the code above in your browser using DataLab