我想保留 FIRST 后的部分。请参阅示例代码。
colnames(df)
"EGAR00001341740_P32_1" "EGAR00001341741_PN32"
Run Code Online (Sandbox Code Playgroud)
我的尝试,但没有给出,P32_1而只是P32哪个是错误的。
sapply(strsplit(colnames(df), split='_', fixed=TRUE), function(x) (x[2]))
Run Code Online (Sandbox Code Playgroud)
所需的输出: P32_1, PN32
我正在开发一个闪亮的应用程序,用户可以上传文件并选择 X 参数,然后按下按钮,它会生成 5 个图(ggplot2 和 barplot)以及动态数据表(DT)。另外,我想将我闪亮的应用程序放入 Linux 服务器中。
我用于tempfiles()创建绘图和 DT 的每个文件。
之后,我的问题是:
当用户关闭闪亮的应用程序(关闭窗口)时,临时文件会自动删除吗?
如果没有,我该怎么做才能删除临时文件?
我的尝试:
session$onSessionEnded(function() {
if (!is.null(x1)) {
file.remove(x1)
}
if (!is.null(x2)) {
file.remove(x2)
}
if (!is.null(x3)) {
file.remove(x3)
}
if (!is.null(x4)) {
file.remove(x4)
}
if (!is.null(xx)) {
file.remove(xx)
}
})
Run Code Online (Sandbox Code Playgroud)
或者:
session$onSessionEnded(function() {
files <- list.files(tempdir(), full.names = T, pattern = "^file")
file.remove(files)
})
Run Code Online (Sandbox Code Playgroud)
使用该代码,当用户按下按钮一次时,我会删除临时文件,如果用户按下按钮超过 1 次,则窗口将关闭,并且只会删除最后生成的文件。第二部分删除临时目录中的所有文件,但这会影响其他用户?(我认为是的,这就是为什么我需要另一个解决方案)。
ggplot 和 barplot 生成的 .png 临时文件不会自动删除。
我担心的是,如果临时文件不会自动删除,Linux 服务器会因为大量临时文件而崩溃。
希望你能解答我的疑惑。阿特·琼.
我想将降水数据与 .csv df 合并。我想通了,它应该与光栅包中的“提取”命令一起使用。这是我的降水数据:
str(precipitation_raster_layer)
Formal class 'RasterLayer' [package "raster"] with 12 slots
..@ file :Formal class '.RasterFile' [package "raster"] with 13 slots
Run Code Online (Sandbox Code Playgroud)
这是我与气候相关的援助数据:
str(AID)
'data.frame': 1050 obs. of 21 variables:
$ project_location_id : Factor w/ 1050 levels "P000501_2427123",..: 189 190 191 192 193 194 188 195 196 187 ...
$ precision_code : int 3 3 3 3 3 3 3 3 3 2 ...
$ latitude : num 6.45 6.74 6.47 5.66 6.6 ...
$ longitude : num -1.583 …Run Code Online (Sandbox Code Playgroud)