我正在使用 CRAN 的 googledrive 包。但是,功能 - drive_upload 允许您上传本地文件而不是数据框。有人可以帮忙吗?
问问题
2027 次
4 回答
0
只需将有问题的 data_frame 保存到本地文件即可。大多数基本选项是保存为 CSV 或保存 RData。
例子:
test <- data.frame(a = 1)
tempFileCon <- file()
write.csv(test, file = tempFileCon)
rm(test)
load("test.Rds")
exists("test")
由于澄清了不可能使用临时文件,我们可以使用文件连接。
test <- data.frame(a = 1)
tempFileCon <- file()
write.csv(test, file = tempFileCon)
现在我们在内存中有文件连接,我们可以使用它来提供其他功能。警告 - 使用文字对象名称来解决它,而不是像使用实际文件那样使用引号。
于 2018-07-12T10:47:19.007 回答
0
这可以通过两种方式完成。就像其他人提到的那样,可以创建一个本地文件并上传。也可以在您的驱动器中创建一个新的电子表格。此电子表格将在您的驱动器的主文件夹中创建。如果您希望它存储在其他地方,您可以在创建后移动它。
# install the packages
install.packages("googledrive", "googlesheets4")
# load the libraries
library(googledrive)
library(googlesheets4)
## With local storage
# Locally store the file
write.csv(x = iris, file = "iris.csv")
# Upload the file
drive_upload(media = "iris.csv", type='spreadsheet')
## Direct storage
# Create an empty spreadsheet. It is stored as an object with a sheet_id and drive_id
ss <- gs4_create(name = "my_spreadsheet", sheets = "Sheet 1")
# Put the data.frame in the spreadsheet and provide the sheet_id so it can be found
sheet_write(data=iris, ss = ss, sheet ="Sheet 1")
# Move your spreadsheet to the desired location
drive_mv(file = ss, path = "my_creations/awesome location/")
于 2021-03-29T18:01:03.590 回答
0
您可以使用 googlesheets 包中的 gs_add_row 来实现此目的。此 API 直接接受数据帧作为输入参数,并将数据上传到指定的谷歌表格。不需要本地文件。
从 ?gs_add_row 的帮助部分:
“如果输入是二维的,我们在内部每个输入行调用一次 gs_add_row。”
于 2020-01-03T13:32:41.693 回答
0
不幸的是,我找不到直接向上推送数据框的方法,而只是为其他试图完成这个问题所涉及的基础知识的人提供文档,使用以下代码编写本地 .csv,然后将其反弹tidyverse::googledrive
以表达自己作为 googlesheet。
write_csv(iris, 'df_iris.csv')
drive_upload('df_iris.csv', type='spreadsheet')
于 2019-05-02T05:52:31.903 回答