[R] Value passing in print option

David Winsemius dwinsemius at comcast.net
Mon Jul 20 22:16:56 CEST 2015


On Jul 19, 2015, at 11:48 PM, Partha Sinha wrote:

> i want to pass a value with print option
> x<-10
> y<2*x
> print("Current value of y is " ) # confused dont know how to pass value
> 
> i want output as Current value of y is 10

With that code we really do not have any assurance that y is 10 (or anything for that matter), and if you meant to type y <- 2*x it would be 20, not 10.

The sprintf function is often used:

 x<-10
y <- 2*x
 sprintf("Current value of y is %d", y)
[1] "Current value of y is 20"


> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list