0

the question is quite simple but I haven't find any answers on google or in the ?options function of R.

I actually updated my R and RStudio version and since then, each time I use a function such as memory.limit(), the output is given to me as bytes instead of megabytes or gigabytes. This is not a real problem but I find more convenient to read 32 000MB instead of 32000000000 bytes.

I know this is probably in some options but even looking at ?memory.limit it seems there's no units or format as arguments.

As far as coding goes I want (MB) :

memory.limit() 32000 

instead of (bytes) :

memory.limit() 32000000000 

Please note that I don't want a function converting bytes to megabytes, I simply want to change the print behavior of R in this regard.

Thank you.

3
  • 1
    Actually, I see different results in RStudio versus running Rgui or R in a terminal. Apparently this is an RStudio bug. Commented Jan 10, 2020 at 22:46
  • 1
    Apparently this has been fixed in recent RStudio builds: see github.com/rstudio/rstudio/issues/4986 Commented Jan 10, 2020 at 22:52
  • Thanks for the comment, no I'm not looking at a different function, like I said I have 2 computer and the one not updated is getting the ouput I desire. I'll take a look at the link, thanks a lot! Commented Jan 11, 2020 at 23:39

1 Answer 1

1

Try using format().

format(memory.limit(), units = "Mb") 

Also good to know:

format(thing_to_format, units = 'auto') 
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer. I am actually aware of using the format() function this way but this is not what I am looking for. I simply want to use memory.limit() and have MB or GB has units without having to specify it every time. I don't know why the print behavior of this function changed after the update of R.
Make your own function. `mem_lim <- function(){format(memory.limit(), units = 'Mb')}
Thanks, I know I can do it this way but that's the point, I shouldn't have too. Base R used to do it just fine. On my other computer, it is still working just fine, so I just want to know how to change that back.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.