我正在使用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
答案 0 :(得分:3)
为什么不只提供文件的完整路径?
尝试打印警告-他们可能会提到找不到文件。
如果需要文件,请设置mustWork=T
。
什么是
fn <- system.file("misc", "zaki2.txt", package = "arulesSequences", mustWork=T)
和
fn2 <- system.file("misc/zaki2.txt", package = "arulesSequences", mustWork=T)
答案 1 :(得分:3)
您还记得cSPADE要求按sequenceID和eventID对数据进行排序吗?
x <- x[order(x$sequenceID, x$eventID), ]
答案 2 :(得分:3)
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
目录:
cspade(x, parameter = list(support = 0.1, maxsize = 1, maxlen = 1),
control = list(verbose = TRUE), tmpdir="~/cspadetmp")
答案 3 :(得分:3)
这是因为您没有获得对临时文件夹“ C:\ Users \ ERKANE〜1 \ AppData \ Local \ Temp \ RtmpohPsWy”的写许可权。
您可以以管理员身份而不是Rstudio身份运行R.exe,或删除临时文件夹的只读属性。
答案 4 :(得分:0)
如果您的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
这大概是 DID 的工作方式:
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'))