Sunday, 15 June 2014

r - Remove connection object immediately after closing connection -



r - Remove connection object immediately after closing connection -

this two-part question regarding next chunk of code.

> ## ran rm(list = ls()) prior next > closeallconnections() > tc <- textconnection("messages", "w") > isopen(tc) # [1] true > close(tc) > ls() # [1] "messages" "tc" > is.object(tc) # [1] true > class(tc) # [1] "textconnection" "connection" > tc # error in summary.connection(x) : invalid connection

why isn't tc removed list of objects, ls(), when tc connection closed, , invalid connection mean? there reason why r keeps tc in list?

is there way remove object list after it's closed? don't want phone call rm() if it's not necessary. perhaps missed argument somewhere while scanning help files.

the reason of import because have function called list.objects returns error after run above code, not otherwise (possibly because tc has 2 classes).

for 1., tc isn't removed list of objects because close doesn't delete variable utilize contain pointer connection. rather, close closes pointer , removes open file connections list (see showconnections). variable contains pointer still exists, it's pointer points nowhere. explains why error when type tc after close it, you're trying @ file connection goes nowhere.

for 2., what's hard close(tc); rm(tc)? hardly more typing if there "delete first argument" parameter.

r

No comments:

Post a Comment