Displaying 20 results from an estimated 30000 matches similar to: "Flag '#' in sprintf() format string "%#x"?"
2009 Mar 26
1
typo in sprintf format string segfaults R
typo as simple as %S instead of %s segfaults R devel:
*** R 2.9.0 (svn -r 47821) [/share/research/R-devel/20090203/lib64/R]
***
> sprintf("%S%d", "aaa", 1)
*** caught segfault ***
address 0x8000, cause 'memory not mapped'
Traceback:
1: sprintf("%S%d", "aaa", 1)
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit
2013 Dec 17
3
In-string variable/symbol substitution: What formats/syntax is out there?
Hi,
I'm try to collect a list of methods/packages available in R for doing
in-string variable/symbol substitution, e.g. someFcn("pi=${pi}"),
anotherFcn("pi=@pi@") and so on becomes "pi=3.141593". I am aware of
the following:
** gsubfn() in the 'gsubfn' package, e.g.
> gsubfn( , , "pi = $pi, 2pi = `2*pi`")
[1] "pi = 3.14159265358979,
2019 May 31
2
use of buffers in sprintf and snprintf
No, that will make it even worse since you'll be declaring a lot more memory that you actually have.
The real problem is that you're ignoring the truncation, so you probably want to use something like
if (snprintf(tempname, sizeof(tempname), "%s.%d", of1name, j) >= sizeof(tempname)) Rf_error("file name is too long");
BTW: most OSes systems have a path limits that
2003 Oct 31
1
strange sprintf() behaviour ?
This is quite strange behaviour - at least for R-novice as myself....
Consider this:
> testf <- function() { x <-2; sprintf("%s %f", "x =", x); return(x) }
> result <- testf()
> testf <- function() { x <-2; sprintf("%s %f", "x =", x) }
> result <- testf()
> testf()
[1] "x = 2.000000"
Apparently adding return()
2008 Sep 15
4
sprintf does not fill with "0"?!
Hello,
please look here:
=================================================================
>
> sprintf("%03s", as.character(1:5))
[1] " 1" " 2" " 3" " 4" " 5"
>
=================================================================
There should be a leading "0" isntead of space-chars?!
I use R version
2009 May 17
1
sprintf() question
When I type the following, I get results different from what I expected.
> sprintf('%a',3)
[1] "0x1.8"
Shouldn't the result be
[1] "0x1.8p+2"
I read through the help ?sprintf and didn't find anything that changed my expectation. What am I misunderstanding? I am using R-2.9.0 binary from CRAN on Windows XP Pro, and my session info is
>
2009 May 17
1
sprintf() question
When I type the following, I get results different from what I expected.
> sprintf('%a',3)
[1] "0x1.8"
Shouldn't the result be
[1] "0x1.8p+2"
I read through the help ?sprintf and didn't find anything that changed my expectation. What am I misunderstanding? I am using R-2.9.0 binary from CRAN on Windows XP Pro, and my session info is
>
2002 May 14
2
NaN/NA and sprintf double format
With a (late prerelease of) 1.5.0 on Windows, using sprintf on NaN
yields garbage when the number of decimal is specified while it
works fine for NA:
> sprintf("%.2f", NA)
[1] "0.00"
> sprintf("%.2f", NaN)
[1] "-1.#J"
Not specifying the decimal precision lets both print garbage:
> sprintf("%f", NaN)
[1] "-1.#IND00"
>
2009 Oct 12
2
SPRINTF option : format %1$s not supported
Hi,
With 1.6.1.7-rc2, doc says:
select*CLI>
-= Info about function 'SPRINTF' =-
[Syntax]
SPRINTF(<format>,<arg1>[,...<argN>])
[Synopsis]
Format a variable according to a format string
[Description]
Parses the format string specified and returns a string matching that
format.
Supports most options supported by sprintf(3). Returns a shortened string
if
a format
2008 Nov 13
1
R crashes on sprintf with bad format specification (PR#13283)
Full_Name: Oren Cheyette
Version: 2.7.2
OS: Win XP
Submission from: (NULL) (64.161.123.194)
Enter the following at the R command prompt:
> sprintf("A %S %S %S XYZ", 1, 1, 1);
Note the erroneous capitalized %S instead of %s and the numeric inputs instead
of strings. With strings there's no crash - R reports bad format
specifications.
2006 Jul 11
1
problem of fixed-formated output using sprintf
Dear R users:
I'm trying to generate a output file with fixed format using function "sprintf" in R. However, the execution time in R is very long even the toy data (smaller size df) seems to work fine. The syntax that I used is as follows:
df.fmt <- sprintf("%2s%2s%2.4f", df$v1, df$v2, df$v3)
write.table(df.fmt, output.name,...)
The actual dataset is a df with the
2003 Aug 21
1
how to specify format of floats for the output file
I'd like to write some numbers to an external file that looks "pretty" (e.g,
decimal points aligned, same number of decimals). For example, if using
sprintf(), "%5.1f" can be used to specify the format of the float to be printed
on screen. How can I do the same if I want to write an output file instead? I
have tried cat and write.table, but none of them worked so far.
2009 Mar 20
1
sprintf causes a segfault (PR#13613)
Full_Name: Wacek Kusnierczyk
Version: 2.8.0 and 2.10.0 r48163
OS: Ubuntu 8.04 Linux 32bit
Submission from: (NULL) (129.241.198.172)
the following code illustrates a problem with sprintf which consistently causes
a segfault when applied to certain type of arguments. it also shows
inconsistent consequences of the segfault:
(e = tryCatch(stop(), error=identity))
# e is an error object
2003 Jan 14
1
2.5.6pre1 bombs on Sunos4 in popthelp.c on use of sprintf
2.5.6pre1 bombs on Sunos4 gcc with these errors
popt/popthelp.c: In function `singleOptionDefaultValue':
popt/popthelp.c:137: invalid operands to binary +
popt/popthelp.c:141: invalid operands to binary +
popt/popthelp.c:145: invalid operands to binary +
popt/popthelp.c:149: invalid operands to binary +
because it's depending on sprintf to return the number of bytes
2012 Jul 30
2
sprintf doesn't care of escape characters
Hi.
I am having trouble with something that should be simple. I am unable
to get sprintf using escape sequences:
> sprintf("a\nb")
[1] "a\nb"
> sprintf("a\"bc\"d")
[1] "a\"bc\"d"
But it seems to need them any way:
> sprintf("a\"bc"d")
Error: unexpected symbol in "sprintf("a\"bc"d"
2006 May 03
3
sprintf question
How would one go about getting sprintf to use the
values of a vector without having to specify each
argument individually?
> v <- c(1, 2, -1.197114, 0.1596687)
> iv <- c(3, 1, 2, 4)
> sprintf("%9.2f\t%d\t%d\t%8.3f", v[3], v[1], v[2], v[4])
[1] " -1.20\t1\t2\t 0.160"
Essentially, desired effect would be something like:
>
2009 Jun 05
1
Bug in print.Arima and patch
Dear List,
A posting to R-Help exposed this problem with the print method for
objects of class Arima:
> set.seed(1)
> x <- arima.sim(n = 100, list(ar = 0.8897, ma = -0.2279))
> mod <- arima(x, order = c(1,0,1))
> coefs <- coef(mod)
> mod2 <- arima(x, order = c(1,0,1), fixed = coefs)
> mod2
Call:
arima(x = x, order = c(1, 0, 1), fixed = coefs)
Coefficients:
Error
2009 Dec 21
2
a little bug for the function 'sprintf' (PR#14161)
Dear R-ers,
I am a gratuate student from South China University of Technology. I fond
the function 'sprintf' in R2.10.1 have a little bug(?):
When you type in the example codes:
> sprintf("%s is %f feet tall\n", "Sven", 7.1)
and R returns:
[1] "Sven is 7.100000 feet tall\n"
this is very different from the 'sprintf' function in C/C++, for in
2020 Sep 20
2
sprintf, check number of parameters
Dear R developers,
I am wondering if this should raise an error or a warning.
> sprintf('%.f, %.f', 1, 2, 3)
[1] "1, 2"
I am aware that R has ?numbered? sprintf arguments (sprintf('%1$.f', ?), and in that case, omissing of specific arguments may be intended. But in the usual syntax, omission of an argument is probably a mistake.
Thank you for your consideration.
2010 May 11
2
sprintf funny behavior
> sprintf("%d",4)
[1] "4"
> for(i in 1:4) sprintf("%d",4)
> for(i in 1:4) print(4)
[1] 4
[1] 4
[1] 4
[1] 4
>
Why doesn't sprintf like the for loop here