繁体   English   中英

arulesSequences 中的 cspade 函数抛出连接错误

[英]cspade function in arulesSequences throws connection error

我正在使用arulesSequences R 库。 这部分代码工作正常:

x <- read_baskets(con = system.file("misc", "zaki2.txt", package = "arulesSequences"), info = c('sequenceID', 'eventID', 'SIZE', 'items'))

zaki2.txt位于

C:\\Users\\USERNAME\\Documents\\R\\win-library\\3.5\\arulesSequences\\misc

但是,当我运行以下代码时:

s1 <- cspade(x, parameter = list(support = 0.1, maxsize = 1, maxlen = 1), control = list(verbose = TRUE))

我收到以下错误:

Error in file(con, "r") : cannot open the connection
      3. file(con, "r") 
      2. read_spade(con = out, labels = itemLabels(data), transactions = if (control@tidLists) data, class = class) 
      1. cspade(x, parameter = list(support = 0.1, maxsize = 1, maxlen = 1), control = list(verbose = TRUE))

我只是想知道为什么会出现这种连接问题。 我对该文件夹进行了完全访问控制(我使用的是 Windows 10),但仍然收到相同的错误。 有什么帮助吗?

更新

我找到了有关错误的更多详细信息。 我查了下这个文件夹,目录里好像没有*.out文件。

reading sequences ...cannot open file 
'C:\Users\ERKANE~1\AppData\Local\Temp\RtmpohPsWy\cspade3894f1b4b9f.out': No 
such file or directoryError in file(con, "r") : cannot open the connection

这是因为您没有获得临时文件夹“C:\\Users\\ERKANE~1\\AppData\\Local\\Temp\\RtmpohPsWy”的写权限。

您可以以管理员身份运行 R.exe 而不是 Rstudio,或者删除临时文件夹的只读属性。

为什么不提供文件的完整路径?

尝试打印警告 - 他们可能提到找不到文件。

如果您需要该文件,请设置mustWork=T

什么是输出

fn <- system.file("misc", "zaki2.txt", package = "arulesSequences", mustWork=T)

fn2 <- system.file("misc/zaki2.txt", package = "arulesSequences", mustWork=T)

您是否记得按照 cSPADE 的要求按 sequenceID 和 eventID 对数据进行排序?

x <- x[order(x$sequenceID, x$eventID), ]

cspade使用临时文件和大量系统调用。 帮助页面说:

Temporary files may not be deleted until the end of the R session if the call is interrupted. 

The current working directory (see getwd) must be writable. 

它写入文件的位置有很多,例如这部分代码:

exe <- "bin"
if (.Platform$r_arch != "") 
    exe <- file.path(exe, .Platform$r_arch)
exe <- system.file(exe, package = "arulesSequences")
file <- tempfile(pattern = "cspade", tmpdir)
on.exit(unlink(paste(file, "*", sep = ".")))

该错误表明有问题的位置out ,其定义为:

out <- paste(file, "stdout", sep = ".")

所以我怀疑这可能是在cspade调用开始时创建的临时目录的问题。 您可能希望设置一个目录以供显式使用,例如,如果您在cspadetmp目录中创建了一个cspadetmp目录:

cspade(x, parameter = list(support = 0.1, maxsize = 1, maxlen = 1),
  control = list(verbose = TRUE), tmpdir="~/cspadetmp")

如果您的 gui 是 RStudio,而不是 Rgui.exe,并且您遇到“无法打开...”错误 -

并不工作:

library(arulesSequences)
data(zaki)
s <- cspade(zaki, parameter = list(support = 0, maxsize = 1, maxlen = 1), control   = list(verbose = TRUE))
# parameter specification:
# support : 0
# maxsize : 1
# maxlen  : 1
# 
# algorithmic control:
# bfstype  : FALSE
# verbose  :  TRUE
# summary  : FALSE
# tidLists : FALSE
# 
# preprocessing ...CONF 4 9 2.7 2.5
# MINSUPPORT 1 4
# MINMAX 1 4
# 1 SUPP 4
# 2 SUPP 4
# 3 SUPP 1
# 4 SUPP 2
# 5 SUPP 1
# 6 SUPP 4
# 7 SUPP 1
# 8 SUPP 1
# numfreq 8 :  0 SUMSUP SUMDIFF = 0 0
# EXTRARYSZ 1232896
# OPENED C:\Users\lukeA\AppData\Local\Temp\Rtmp6Ncns7\cspade1b8c67e92f8e.idx
# OFF 9 54
# Wrote Offt 0.00200415
# BOUNDS 1 5
# WROTE INVERT 0.000996828
# Total elapsed time 0.0100021
# 1 partition(s), 0 MB [0.12s]
# mining transactions ...MINSUPPORT 1 out of 4 sequences
# 1 -- 4 4 
# 2 -- 4 4 
# 3 -- 1 1 
# 4 -- 2 2 
# 5 -- 1 1 
# 6 -- 4 4 
# 7 -- 1 1 
# 8 -- 1 1 
# NA MB [0.13s]
# reading sequences ...Error in file(con, "r") : cannot open the connection
# In addition: Warning message:
#   In file(con, "r") :
#   cannot open file 'C:\Users\lukeA\AppData\Local\Temp\Rtmp6Ncns7\cspade1b8c67e92f8e.out': No such file or directory

这大概确实有效:

library(arulesSequences)
data(zaki)
old_gui <- .Platform$GUI
unlockBinding(".Platform", env =  as.environment('package:base'))
.Platform$GUI <<- "Rgui"
s <- cspade(zaki, parameter = list(support = 0, maxsize = 1, maxlen = 1), control   = list(verbose = TRUE))
# 
# parameter specification:
# support : 0
# maxsize : 1
# maxlen  : 1
# 
# algorithmic control:
# bfstype  : FALSE
# verbose  :  TRUE
# summary  : FALSE
# tidLists : FALSE
# 
# preprocessing ... 1 partition(s), 0 MB [0.14s]
# mining transactions ... 0 MB [0.11s]
# reading sequences ... [0.03s]
# 
# total elapsed time: 0.28s
.Platform$GUI <<- old_gui
lockBinding(".Platform", env =  as.environment('package:base'))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM