[R] getting the name of a single object in R for debugging output

Henrique Dallazuanna wwwhsd at gmail.com
Wed Nov 18 12:10:25 CET 2009


Try this:

debugPrint <- function(x, ...){
	print(sprintf("%s: %d", deparse(substitute(x)), x), ...)
}

On Wed, Nov 18, 2009 at 8:35 AM, Andrew <nodecorum at yahoo.com> wrote:
> I often use a debug flag (set to TRUE) to turn on various debugging print statements in my R scripts.  I was thinking I should create a function debugPrint(object,debugFlag),
> to print out the object name and contents if the debugFlag is set to TRUE.  Then I wouldn't have to make my script ugly(..er) than it already is by adding IF statements all over the place.  I've seen how ls() dumps object names, but how do I get access to the character representation of the name of an object.
>
> E.g.
>
> myVar<- 10
>
> print(myVar) produces "10"
>
> I'd like to print out something like " myVar : 10"
>
> I'd appreciate any suggestions.
>
> Regards,
>
> Andrew
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list