我想HTML字符实体转换喜欢
&到&或
>以>
对于Perl存在的包HTML :: Entities可以做到这一点,但我在R中找不到类似的东西.
我也尝试过iconv()但无法获得令人满意的结果.也许还有一种方法可以使用这个XML包,但我还没想出来.
在我基于Debian的机器上使用R的并行软件包玩了一段时间后,我仍然无法找到一种方法来在计算后删除所有僵尸子进程.
我正在寻找一个通用的OS独立解决方案.
下面是一个简单的脚本,说明了2个内核的问题:
library(parallel)
testfun <- function(){TRUE}
cltype <- ifelse(.Platform$OS.type != "windows", "FORK", "PSOCK")
cl <- makeCluster(2, type = cltype)
p <- clusterCall(cl, testfun)
stopCluster(cl)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这个脚本在进程表中留下了两个僵尸进程,只有在R关闭时才会被杀死.
我正在使用strptime(...)我的包的功能.我需要使用特定的本地设置解析字符串,并将其用作Sys.setlocale解决方法以获取英语本地化设置.为减少副作用,之后恢复先前的本地设置.该函数的基本代码片段如下所示:
#parameter settings
sometext <- "Mon, 14 Mar 2011 23:42:16 GMT"
timeFormat <- "%a, %d %b %Y %H:%M:%S"
timeZone <- "GMT"
#get current locale
loc <- Sys.getlocale("LC_TIME")
#set british localization
dummy <- Sys.setlocale("LC_TIME", "en_GB.UTF-8")
#parse datetime string
time <- strptime(sometext, format = timeFormat, tz= timeZone)
#set local back
dummy <- Sys.setlocale("LC_TIME", loc)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我的同事在使用此功能时会收到以下警告:
In Sys.setlocale("LC_TIME", "en_GB.UTF-8") :
OS reports request to set locale to "en_GB.UTF-8" cannot be honored
Run Code Online (Sandbox Code Playgroud)
在我的电脑上一切正常.是否有更好的(并且独立于已安装的R本地化)执行此任务的方式?通常我想使用strptime,因为它允许非常灵活地解析日期时间字符串.
我已经使用S4类编写了一个包,并希望使用函数rbind,cbind和这些定义的类.
因为似乎不可能直接定义rbind和定义cbind为我定义的S4方法rbind2,cbind2而是:
setMethod("rbind2", signature(x="ClassA", y = "ANY"),
function(x, y) {
# Do stuff ...
})
setMethod("cbind2", signature(x="ClassA", y = "ANY"),
function(x, y) {
# Do stuff ...
})
Run Code Online (Sandbox Code Playgroud)
从?cbind2我了解到,需要激活这些函数来methods:::bind_activation从base替换rbind和cbind.
我使用以下.onLoad函数将调用包含在包文件R/zzz.R中:
.onLoad <- function(...) {
# Bind activation of cbind(2) and rbind(2) for S4 classes
methods:::bind_activation(TRUE)
}
Run Code Online (Sandbox Code Playgroud)
这按预期工作.但是,运行R CMD检查我现在得到以下注释,因为我在方法中使用了未导出的函数:
* checking dependencies in R code ... NOTE
Unexported object imported by a ':::' call: 'methods:::bind_activation'
See the …Run Code Online (Sandbox Code Playgroud) 在我使用Sqlite和FTS表在我的应用程序中实现全文搜索功能后,我会感兴趣的是从我的FTS表中检索FULL倒排索引的高效方法.实际上 - 我需要一个结果表,包括所有术语之间的映射 - > docid - >出现次数.
遵循Sqlite FTS 文档 - 在创建表之后
-- Create an FTS4 table
CREATE VIRTUAL TABLE ft USING fts4(x, y);
-- Create an fts4aux table to access the full-text index for table "ft"
CREATE VIRTUAL TABLE ft_terms USING fts4aux(ft);
Run Code Online (Sandbox Code Playgroud)
...和内容插入......
INSERT INTO ft(x, y) VALUES('Apple banana', 'Cherry');
INSERT INTO ft(x, y) VALUES('Banana Date Date', 'cherry');
INSERT INTO ft(x, y) VALUES('Cherry Elderberry', 'Elderberry');
Run Code Online (Sandbox Code Playgroud)
...而不是像FTS AUX表中的所有文件中只有条款和出现次数......
SELECT term, col, documents, occurrences FROM ft_terms;
-- apple | * …Run Code Online (Sandbox Code Playgroud)