Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6987041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:53:08+00:00 2026-05-27T18:53:08+00:00

The default value of a parameter of my function contains a %. This seems

  • 0

The default value of a parameter of my function contains a “%”. This seems to be a problem for roxygen, it produces a lot of warnings and R CMD check fails when trying to build latex documentation.

How can I make this function (and its documentation) work? Using %% or \% instead of % does not help.

#' Test escape \% from in-source documentation (roxygen).
#'
#' What happens when parameters contain special latex characters? 
#'
#' @param x unsuspicious parameter 
#' @param format sprintf format string (default "\%5.0f")
#'
#' @return formatted string
#' @export
#' @author Karsten Weinert
testroxy <- function(x, format = "%5.0f") {
  sprintf(format,x)
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:53:08+00:00Added an answer on May 27, 2026 at 6:53 pm
    #!/usr/bin/perl
    use strict;
    use File::Temp qw/tempfile/;
    use File::Copy;
    
    my $usage = <<EOD
    
      $0 file1.Rd [file2.Rd ...]
    
      When using roxygen to generate documentation for an R pacakge, if a default
      argument has a percent sign in it then roxygen will copy it directly into
      the .Rd file. Since .Rd is basically latex, this will be interpreted as a
      comment and case the file to be parsed incorrectly.
    
      For percent signs elsewhere in your documentation, for example in the
      description of one of the parameters, you should use "\%" so parse_Rd
      interprets it correctly.
    
      But you cannot do this in the default arguments because they have to be
      valid R code, too.
    
      Since the .Rd files are automatically generated they should not have
      any latex comments in them anyway.
    
      This script escapes every unescaped % within the file.
    
      The .Rd files are modified in place, since it would be easy to
      generate them again with R CMD roxygen.
    
    EOD
    ;
    
    my $n_tot = 0;
    my $n_file = @ARGV;
    my $n_esc_file = 0;
    foreach my $fn (@ARGV)  {
    
      print STDERR ' ' x 100, "\rWorking on $fn\t";
      open my $fh, $fn or die "Couldn't open $fn: $!";
      my ($tmp_fh, $tmp_fn) = tempfile();
    
      my $n;
      while(<$fh>)  {
        $n += s/(?<!\\)%/\\%/g;  # if % is not preceded with backslash then replace it with '\%'
        print $tmp_fh $_;
      }
      $n_tot += $n;
      $n_esc_file ++ if $n;
      print "Escaped $n '%'\n" if $n;
      close $tmp_fh;
      move($tmp_fn => $fn);
    }
    
    print "\n";
    
    print "$n_file files parsed\n";
    print "$n_esc_file contained at least one unescaped %\n";
    print "$n_tot total % were escaped\n";
    

    This is my inelegant solution. Save the perl script as, for example, escape_percents.pl, then the sequence would be like this:

    R CMD roxygen my.package
    perl escape_percents.pl my.package.roxygen/man/*.Rd
    R CMD install my.package.roxygen
    

    This may introduce more problems, for example if you have example code using %% as the modulus operator, but it has been handy for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the place for the default parameter value? Just in function definition, or declaration,
I tried changing a default parameter value with this: ALTER PROCEDURE [dbo].[my_sp] @currentDate datetime
I have some questions about the default values in a function parameter list Is
Is it legal to define a default value for a parameter the way I
When I set a default value formula for a date parameter in SSRS, such
I can define default value in domain by this way : class ProcessingPriority {
I need to add default value column in SqlServer Compact....i am new to this
I was reading this today: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#default-parameter-values and I can't seem to understand what's happening
I'm having a problem with optional function parameter in C++ What I'm trying to
Possible Duplicate: Default value to a parameter while passing by reference in C++ Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.