[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){
require(caTools)
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)
write.socket(s,request)
response = read.socket(s,8192)
close.socket(s)
header = sub('^(.*)\r\n\r\n(.*)$','\\1',response)
rest = sub('^(.*)\r\n\r\n(.*)$','\\2',response)
unlist(strsplit(rest,'\n'))
}
Here what Phil proposed to use instead of source()
eval(parse(text=getauth('http://whatever.com/path/to/file',user,pass)))
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...
eval(parse(text=getauth('http://tinyurl.com/ne5bl3',user,pass)))
I get NULL.
Please, use DummyDummy as user and dummy as pass if you want to try it.
Thanks.
Thanks in advance for any insight!
Greetings,
Ricardo
--
Ricardo Rodríguez
Your XEN ICT Team
More information about the R-help
mailing list