Skip to content

Commit

Permalink
Use updated importFrom recs
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Mar 12, 2014
1 parent 2020bb9 commit 97569cf
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 44 deletions.
8 changes: 0 additions & 8 deletions NAMESPACE
Expand Up @@ -94,13 +94,5 @@ export(roxygenize)
export(update_collate)
export(upgradeRoxygen)
import(stringr)
importFrom(Rcpp,evalCpp)
importFrom(Rcpp,sourceCpp)
importFrom(brew,brew)
importFrom(digest,digest)
importFrom(methods,getClass)
importFrom(methods,getGeneric)
importFrom(methods,getMethod)
importFrom(methods,getRefClass)
importFrom(methods,setPackageName)
useDynLib(roxygen2)
1 change: 0 additions & 1 deletion R/RcppExports.R
Expand Up @@ -5,7 +5,6 @@ rdComplete <- function(string) {
.Call('roxygen2_rdComplete', PACKAGE = 'roxygen2', string)
}

#' @importFrom Rcpp evalCpp
splitByWhitespace <- function(string) {
.Call('roxygen2_splitByWhitespace', PACKAGE = 'roxygen2', string)
}
Expand Down
12 changes: 4 additions & 8 deletions R/object-from-call.R
Expand Up @@ -48,34 +48,30 @@ parser_assignment <- function(call, env, block) {
}


#' @importFrom methods getClass
parser_setClass <- function(call, env, block) {
name <- as.character(call$Class)
value <- getClass(name, where = env)
value <- methods::getClass(name, where = env)

object(value)
}

#' @importFrom methods getRefClass
parser_setRefClass <- function(call, env, block) {
name <- as.character(call$Class)
value <- getClass(name, where = env)
value <- methods::getClass(name, where = env)

object(value)
}

#' @importFrom methods getGeneric
parser_setGeneric <- function(call, env, block) {
name <- as.character(call$name)
value <- getGeneric(name, where = env)
value <- methods::getGeneric(name, where = env)

object(value)
}

#' @importFrom methods getMethod
parser_setMethod <- function(call, env, block) {
name <- as.character(call$f)
value <- getMethod(name, eval(call$signature), where = env)
value <- methods::getMethod(name, eval(call$signature), where = env)
value@.Data <- extract_method_fun(value@.Data)

object(value)
Expand Down
1 change: 0 additions & 1 deletion R/roclet-rd.R
Expand Up @@ -53,7 +53,6 @@ rd_roclet <- function() {
}

#' @export
#' @importFrom digest digest
roc_process.had <- function(roclet, parsed, base_path, options = list()) {
env <- parsed$env
partita <- parsed$blocks
Expand Down
3 changes: 1 addition & 2 deletions R/source.R
Expand Up @@ -8,7 +8,6 @@
#' @param path Path to a package
#' @return an environment, in to which all R files in the directory were
#' sourced.
#' @importFrom methods setPackageName
#' @keywords internal
source_package <- function(path) {
r_path <- file.path(path, "R")
Expand All @@ -18,7 +17,7 @@ source_package <- function(path) {
on.exit(setwd(old_dir))

env <- new.env(parent = globalenv())
setPackageName("roxygen_devtest", env)
methods::setPackageName("roxygen_devtest", env)

load_pkg_dependencies(path)

Expand Down
3 changes: 1 addition & 2 deletions R/template.R
Expand Up @@ -12,9 +12,8 @@ template_find <- function(base_path, template_name) {
path[path_exists][1]
}

#' @importFrom brew brew
template_eval <- function(template_path, vars) {
capture.output(brew(template_path, envir = vars))
capture.output(brew::brew(template_path, envir = vars))
}

process_templates <- function(partitum, base_path) {
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Expand Up @@ -116,8 +116,8 @@ same_contents <- function(path, contents) {

contents <- paste0(paste0(contents, collapse = "\n"), "\n")

text_hash <- digest(contents, serialize = FALSE)
file_hash <- digest(file = path)
text_hash <- digest::digest(contents, serialize = FALSE)
file_hash <- digest::digest(file = path)

identical(text_hash, file_hash)
}
Expand Down
23 changes: 11 additions & 12 deletions src/wrapString.cpp
@@ -1,19 +1,18 @@
#include <Rcpp.h>
using namespace Rcpp;

//' @importFrom Rcpp evalCpp
// [[Rcpp::export]]
std::vector<std::string> splitByWhitespace(std::string string) {
int n = string.length();
std::vector<std::string> out;

std::string acc = "";
char in_string = '\0';
bool in_escape = false;

for(int i = 0; i < n; ++i) {
char cur = string[i];

if (in_string != '\0') {
acc += cur;

Expand All @@ -28,12 +27,12 @@ std::vector<std::string> splitByWhitespace(std::string string) {
if (cur != in_string) {
continue;
}

// String terminates
in_string = '\0';
continue;
}

if (cur == ' ' || cur == '\t' || cur == '\n') {
out.push_back(acc);
acc = "";
Expand All @@ -44,9 +43,9 @@ std::vector<std::string> splitByWhitespace(std::string string) {
acc += cur;
}
}

out.push_back(acc);

return out;
}

Expand All @@ -55,12 +54,12 @@ std::string wrapString(std::string string, int width = 80, int indent = 2) {
std::vector<std::string> pieces = splitByWhitespace(string);
int n = pieces.size();
int cur_width = 0;

std::string out;

for (int i = 0; i < n; ++i) {
int piece_width = pieces[i].size();

if (piece_width + cur_width < width) {
cur_width += piece_width;
if (i != 0) {
Expand All @@ -73,6 +72,6 @@ std::string wrapString(std::string string, int width = 80, int indent = 2) {
}
out += pieces[i];
}

return out;
}
17 changes: 9 additions & 8 deletions vignettes/namespace.Rmd
Expand Up @@ -73,15 +73,19 @@ Use the following guidelines to decide what to export:

## Imports

The `NAMESPACE` also controls which functions from other packages are made available to you package. There are five tags for importing objects into the package:
The `NAMESPACE` also controls which functions from other packages are made available to your package. Only unique directives are saved to the `NAMESPACE` file, so you can repeat them as needed to maintain a close link between the functions where they are needed and the namespace file.

* `@import package` imports all functions, classes and methods from a package.
If you are using just a few functions from another package, call them explicitly with `pkg::fun()`. I no longer recommend using `@importFrom`.

* `@importFrom package functiona functionb ...` imports selected functions.
If you are using many functions from another package, use `@import package` to import them all and make available without using `::`.

* `@importClassesFrom package classa classb ...` imports selected S4 classes.
If you are using S4 you may also need:

* `@importMethodsFrom package methoda methodb ...` imports selected S4 methods.
* `@importClassesFrom package classa classb ...` to import selected S4 classes.

* `@importMethodsFrom package methoda methodb ...` to import selected S4 methods.

To import compiled code from another package, use `@useDynLib`

* `@useDynLib package` imports all compiled functions.

Expand All @@ -91,6 +95,3 @@ The `NAMESPACE` also controls which functions from other packages are made avail
`@useDynLib mypackage, .registration = TRUE` will be inserted as is
into the the NAMESPACE, e.g. `useDynLib(mypackage, .registration = TRUE)`

Only unique directives are saved to the `NAMESPACE` file, so you can
repeat them as needed to maintain a close link between the functions where
they are needed and the namespace file.

0 comments on commit 97569cf

Please sign in to comment.