我希望知道为什么message()比print()打印诊断信息更好.
例如,print()函数是打印R对象的更好选择,例如'iris',message()当我们想要连接字符串时,它更好,例如message("a", "b")短于print(paste0("a", "b")).
但是,我认为与上面列出的简单差异相比,存在更多差异.我已经阅读了这两种方法的文档
但是,似乎它们并没有像我希望的那样提供信息.
如果有人告诉我们哪种情况message()比哪种情况更好print(),为什么我会感激.
每当我们使用"R"命令启动R控制台时,我们可以看到如下消息
R version 3.2.0 (2015-04-16) -- "Full of Ingredients"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in …Run Code Online (Sandbox Code Playgroud) 我的目标是将base64编码"%EB"字符串转换为"\ xEB".然而,一旦我尝试,我发现它很难并且不能通过string.replace或re.sub两者来实现.
我的代码失败如下:
target = '%EB%AF%B8%EB%9F%AC%EC%8A%A4%20%EC%97%A3%EC%A7%80'
target.replace('%','\x')
-> ValueError: invalid \x escape
re.sub('%','\x',target)
-> ValueError: invalid \x escape
Run Code Online (Sandbox Code Playgroud)
更新:
感谢您的评论,我尝试'\ x'和r'\ x',但是,似乎那些不是解决方案.
例如,
target = '%EB%AF%B8%EB%9F%AC%EC%8A%A4%20%EC%97%A3%EC%A7%80'
converted1 = target.replace('%',r'\x')
converted2 = target.replace('%','\\x')
converted1
-> '\\xEB\\xAF\\xB8\\xEB\\x9F\\xAC\\xEC\\x8A\\xA4\\x20\\xEC\\x97\\xA3\\xEC\\xA7\\x80'
converted2
-> '\\xEB\\xAF\\xB8\\xEB\\x9F\\xAC\\xEC\\x8A\\xA4\\x20\\xEC\\x97\\xA3\\xEC\\xA7\\x80'
Run Code Online (Sandbox Code Playgroud)
结果:
print converted1
\xEB\xAF\xB8\xEB\x9F\xAC\xEC\x8A\xA4\x20\xEC\x97\xA3\xEC\xA7\x80
print converted2
\xEB\xAF\xB8\xEB\x9F\xAC\xEC\x8A\xA4\x20\xEC\x97\xA3\xEC\xA7\x80
Run Code Online (Sandbox Code Playgroud)
我想要的是:
print "\xEB\xAF\xB8\xEB\x9F\xAC\xEC\x8A\xA4\x20\xEC\x97\xA3\xEC\xA7\x80"
??? ??
Run Code Online (Sandbox Code Playgroud)