PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 17, 2022

[FIXED] How to hide or disable in-function printed message

 September 17, 2022     printing, r     No comments   

Issue

Suppose I have a function such as:

ff <- function(x) {
  cat(x, "\n")
  x^2}

And run it by:

y <- ff(5)
# 5 
y
# [1] 25

My question is how to disable or hide the 5 printed from cat(x, "\n") such as:

y <- ff(5)
y
# [1] 25

Solution

You can use capture.output with invisible

> invisible(capture.output(y <- ff(2)))
> y
[1] 4

or sink

> sink("file")
> y <- ff(2)
> sink()
> y
[1] 4


Answered By - romants
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing