[R] using cat()

[Ricardo Rodriguez] Your XEN ICT Team webmaster at xen.net
Fri Aug 7 09:01:38 CEST 2009

Thanks, Steve,

Steve Lianoglou wrote:
> It seems like you're asking to use cat() for something it's not meant 
> to do. cat() is generally used to write output, either to the screen 
> or to a file.
Sorry for not adding an example to my first post! And yes, I was trying 
to use it for something it is not meant to.
> You can use cat *in* a function to print the value of a variable, but 
> you can't "reach into" a function to pull out a variable's value. Are 
> you trying to debug something? See: ?debug to step through a function 
> to examine what it's doing one step at a time.
Yes, I am trying to discover why a function that Phil Spector sent to 
the list one year and a half ago doesn't do the trick for me (please, 
see http://tinyurl.com/lh3fh4). Here the function (it is intended to 
submit code stored in a restricted access web site accepting Basic 
Authentication; source() works nicely for free access sites, but it 
doesn't manage authentication):

getauth = function(url,user,pass){
   url = sub('^http://','',url)
   getexpr = function(s,g)substring(s,g,g + attr(g,'match.length') - 1)
   host = sub('^(.*?)/(.*)$','\\1',url,perl=TRUE)
   file = sub('^(.*?)/(.*)$','\\2',url,perl=TRUE)
   upb = base64encode(paste(user,pass,sep=':'))
   request = paste('GET /',file,' HTTP/1.1\nHost: 
',host,'\nAuthorization: Basic ',upb,'\n\n',sep='')
   s = make.socket(host,port=80)
   response = read.socket(s,8192)
   header = sub('^(.*)\r\n\r\n(.*)$','\\1',response)
   rest = sub('^(.*)\r\n\r\n(.*)$','\\2',response)

Here what Phil proposed to use instead of source()


At this moment, what I am trying to do is to debug, thanks Steve, this 
function to see where it is failing. Given a real example...


I get NULL.

Please, use DummyDummy as user and dummy as pass if you want to try it. 

Thanks in advance for any insight!



Ricardo Rodríguez
Your XEN ICT Team

More information about the R-help mailing list