Skip to content

Extra } is added by the "Style active file" addin (but not with styler::style_file()) #309

Closed

Description

@jennybc

styler version: 0.0.9

Input file:

#' Use Rcpp
#'
#' Creates `src/` and adds needed packages to `DESCRIPTION`.
#'
#' @inheritParams use_template
#' @export
use_rcpp <- function() {
  use_dependency("Rcpp", "LinkingTo")
  use_dependency("Rcpp", "Imports")

  use_directory("src")
  use_git_ignore(c("*.o", "*.so", "*.dll"), "src")

  if (uses_roxygen()) {
    todo("Include the following roxygen tags somewhere in your package")
    code_block(
      paste0("#' @useDynLib ", project_name(), ", .registration = TRUE"),
      "#' @importFrom Rcpp sourceCpp",
      "NULL"
    )
  } else {
    todo("Include the following directives in your NAMESPACE")
    code_block(
      paste0("useDynLib('", project_name(), "', .registration = TRUE)"),
      "importFrom('Rcpp', 'sourceCpp')"
    )
    edit_file(proj_get(), "NAMESPACE")

  }
  todo("Run document()")
}

Output using "Style active file" addin:

#' Use Rcpp
#'
#' Creates `src/` and adds needed packages to `DESCRIPTION`.
#'
#' @inheritParams use_template
#' @export
use_rcpp <- function() {
  use_dependency("Rcpp", "LinkingTo")
  use_dependency("Rcpp", "Imports")
  
  use_directory("src")
  use_git_ignore(c("*.o", "*.so", "*.dll"), "src")
  
  if (uses_roxygen()) {
    todo("Include the following roxygen tags somewhere in your package")
    code_block(
      paste0("#' @useDynLib ", project_name(), ", .registration = TRUE"),
      "#' @importFrom Rcpp sourceCpp",
      "NULL"
    )
  } else {
    todo("Include the following directives in your NAMESPACE")
    code_block(
      paste0("useDynLib('", project_name(), "', .registration = TRUE)"),
      "importFrom('Rcpp', 'sourceCpp')"
    )
    edit_file(proj_get(), "NAMESPACE")
  }
  todo("Run document()")
}}

It contains an extra trailing } at the very end.

I get a different and correct result with styler::style_file().

Activity

  1. lorenzwalthert commented on Jan 1, 2018

    @lorenzwalthert
    Collaborator

    Thanks for reporting this @jennybc. I think this was reported already (#282) and fixed subsequently (#283) before the CRAN Submission. I therefore suggest you to download the CRAN version of styler and try again.

  2. jennybc commented on Jan 1, 2018

    @jennybc
    MemberAuthor

    Sure enough! Sorry I thought I had the CRAN version and that version number didn't stand out to me as dev.

    Once thing I do notice is that the add in seems to drop my trailing new line. As soon as I save, RStudio adds it back. Do you see that? If so, that should be a separate issue, I guess.

  3. lorenzwalthert commented on Jan 2, 2018

    @lorenzwalthert
    Collaborator

    Yes, I notice the same problematic behaviour regarding EOF line breaks. I opened #310 to discuss that further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions