From 1c4baf6dc28dee26af5092bc4ce72698880f430d Mon Sep 17 00:00:00 2001 From: yutannihilation Date: Wed, 4 Jan 2017 06:31:04 +0900 Subject: [PATCH] ignore roxygen2-generated files (#3373) --- lib/linguist/generated.rb | 17 ++++++++- samples/R/import.Rd | 72 +++++++++++++++++++++++++++++++++++++++ test/test_generated.rb | 3 ++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 samples/R/import.Rd diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index de16e683..41b1101b 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -77,7 +77,8 @@ module Linguist generated_unity3d_meta? || generated_racc? || generated_jflex? || - generated_grammarkit? + generated_grammarkit? || + generated_roxygen2? end # Internal: Is the blob an Xcode file? @@ -433,5 +434,19 @@ module Linguist return false unless lines.count > 1 return lines[0].start_with?("// This is a generated file. Not intended for manual editing.") end + + # Internal: Is this a roxygen2-generated file? + # + # A roxygen2-generated file typically contain: + # % Generated by roxygen2: do not edit by hand + # on the first line. + # + # Return true or false + def generated_roxygen2? + return false unless extname == '.Rd' + return false unless lines.count > 1 + + return lines[0].include?("% Generated by roxygen2: do not edit by hand") + end end end diff --git a/samples/R/import.Rd b/samples/R/import.Rd new file mode 100644 index 00000000..1623d222 --- /dev/null +++ b/samples/R/import.Rd @@ -0,0 +1,72 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hello.R +\name{import} +\alias{import} +\title{Import a module into the current scope} +\usage{ +import(module, attach, attach_operators = TRUE) +} +\arguments{ +\item{module}{an identifier specifying the full module path} + +\item{attach}{if \code{TRUE}, attach the newly loaded module to the object +search path (see \code{Details})} + +\item{attach_operators}{if \code{TRUE}, attach operators of module to the +object search path, even if \code{attach} is \code{FALSE}} +} +\value{ +the loaded module environment (invisible) +} +\description{ +\code{module = import('module')} imports a specified module and makes its +code available via the environment-like object it returns. +} +\details{ +Modules are loaded in an isolated environment which is returned, and +optionally attached to the object search path of the current scope (if +argument \code{attach} is \code{TRUE}). +\code{attach} defaults to \code{FALSE}. However, in interactive code it is +often helpful to attach packages by default. Therefore, in interactive code +invoked directly from the terminal only (i.e. not within modules), +\code{attach} defaults to the value of \code{options('import.attach')}, which +can be set to \code{TRUE} or \code{FALSE} depending on the user’s preference. + +\code{attach_operators} causes \emph{operators} to be attached by default, +because operators can only be invoked in R if they re found in the search +path. Not attaching them therefore drastically limits a module’s usefulness. + +Modules are searched in the module search path \code{options('import.path')}. +This is a vector of paths to consider, from the highest to the lowest +priority. The current directory is \emph{always} considered first. That is, +if a file \code{a.r} exists both in the current directory and in a module +search path, the local file \code{./a.r} will be loaded. + +Module names can be fully qualified to refer to nested paths. See +\code{Examples}. +} +\note{ +Unlike for packages, attaching happens \emph{locally}: if +\code{import} is executed in the global environment, the effect is the same. +Otherwise, the imported module is inserted as the parent of the current +\code{environment()}. When used (globally) \emph{inside} a module, the newly +imported module is only available inside the module’s search path, not +outside it (nor in other modules which might be loaded). +} +\examples{ +# `a.r` is a file in the local directory containing a function `f`. +a = import('a') +a$f() + +# b/c.r is a file in path `b`, containing a function `g`. +import('b/c', attach = TRUE) +g() # No module name qualification necessary + +} +\seealso{ +\code{unload} + +\code{reload} + +\code{module_name} +} \ No newline at end of file diff --git a/test/test_generated.rb b/test/test_generated.rb index db32e8f5..6301d971 100644 --- a/test/test_generated.rb +++ b/test/test_generated.rb @@ -87,5 +87,8 @@ class TestGenerated < Minitest::Test # GrammarKit generated_sample_loading_data("Java/GrammarKit.java") + + # roxygen2 + generated_sample_loading_data("R/import.Rd") end end