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 8739219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:53:24+00:00 2026-06-13T10:53:24+00:00

I’m attempting to make a function for a package that allows the user to

  • 0

I’m attempting to make a function for a package that allows the user to read in data without quotation marks. It works almost as expected except the function turns 3.30 into 3.3 even though the final output is character. How can I get my function to read in elements that are numbers but not to drop trailing zeros. The big picture idea is:

  1. function that reads elements without using quotation marks
  2. function will not discard what R considers non significant zeros
  3. though the elements may look numeric I want them to be outputted as character elements

Here are two attempts and what they out put (one attempt with substitute(...()) and the other with match.call(expand.dots = FALSE):

#attempt #1 
fun <- 
function(...){ 
    substitute(...())
}

fun(3.30, 5.05)

#dropped zero on 3:30 (not what I want)
> fun(3.30, 5.05)
[1] "3.3"  "5.05"

#attempt #2 
fun <- 
function(...){ 
    x <- match.call(expand.dots = FALSE)
    as.character(x[[2]])
}

fun(3.30, 5.05)

#again dropped zero on 3:30 (not what I want)    
> fun(3.30, 5.05)
[1] "3.3"  "5.05"

With quotation marks it outputs what I want but this defeats the purpose of not having to provide quotation marks:

fun('3.30', '5.05')

> fun('3.30', '5.05')
[1] "3.30" "5.05"

PS if someone has a better title for this thread feel free to edit

  • 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-06-13T10:53:25+00:00Added an answer on June 13, 2026 at 10:53 am

    Well there is one way I could think of but it isn’t quite pretty and might not be stable. R also saves history of the entered calls. That could be used to obtain the exact input:

    fun <- 
      function(...){
        savehistory(file <- tempfile())
        hist <- readLines(file)
        args <- hist[length(hist)]
        args <- unlist(regmatches(args,gregexpr("(?<=fun\\().*(?=\\))",args,perl=TRUE)))
        args <- unlist(strsplit(args,split=","))
        as.character(args)
      }
    

    Example:

    > fun(2.20,3.14,pi,0.000000)
    [1] "2.20"     "3.14"     "pi"       "0.000000"
    

    I am not sure how stable this would be, there will probably be a dozen cases it will break. Also, this assumes the function is named fun.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.