我在R中运行一项日常任务,该任务从Outlook中检索电子邮件(附加了csv文件),对csv文件进行一些分析,并将结果数据帧写入公司的本地驱动器。某些早晨,我发现文件尚未交付,并且根据日志,原因是以下错误:
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
Execution halted
Run Code Online (Sandbox Code Playgroud)
我找不到发生这种情况的日子的任何模式。一旦我手动触发任务,它通常运行良好。
我已经在其他问题中看到了此错误,但是这些问题与通过Outlook发送附件有关,而我没有这样做。以下是我访问Outlook和检索数据的代码:
library(RDCOMClient)
outlook_app <- COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpmail:subject = 'My_Subject'"
)
Sys.sleep(5)
results <- search$Results()
for (i in 1:results$Count()) {
if (as.Date("1899-12-30") + floor(results$Item(i)$ReceivedTime())
== as.Date(strptime(Sys.time(),format = "%Y-%m-%d"))) {
email <- results$Item(i)
}
}
attachment_file <- tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
data <- read.csv(attachment_file,sep=",",fileEncoding="UCS-2LE")
Run Code Online (Sandbox Code Playgroud) 我正在训练一个 Keras 模型,该模型位于 Scikit 管道中并进行了一些预处理。Keras 模型定义为
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, Input, Dropout
from tensorflow.keras import optimizers
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.wrappers.scikit_learn import KerasRegressor
from sklearn.pipeline import make_pipeline
def create_model(X_train):
inp = Input(shape=(X_train.shape[1],))
x = Dense(150, activation="relu")(inp)
x = Dropout(0.4)(x)
mean = Dense(1, activation="linear")(x)
train_model_1 = Model(inp, mean)
adam = optimizers.Adam(lr=0.01)
train_model_1.compile(loss=my_loss_function, optimizer=adam)
return train_model_1
clf = KerasRegressor(build_fn=create_model, epochs=250, batch_size=64)
Run Code Online (Sandbox Code Playgroud)
Pipeline然后在with中使用
pipeline = make_pipeline(
other_steps,
clf(X_train)
)
pipeline.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
我想在使用EarlyStopping测试数据 ( X_test, y_test …
我希望用户能够编辑已经加载的DataTable,单击一个按钮,然后将编辑后的版本用作输入来完成工作.因此,在此示例中,如何在单击"更改数据帧"按钮时使新的用户编辑版本显示在"新建"选项卡中?
shinyUI(fluidPage(
titlePanel(),
sidebarLayout(
sidebarPanel(
actionButton("runButton","Change Dataframes")
),
mainPanel(
tabsetPanel(
tabPanel("OldIrisTab",
DT::dataTableOutput("OldIris")),
tabPanel("OldPetrolTab",
DT::dataTableOutput("OldPetrol")),
tabPanel("NewIrisTab",
DT::dataTableOutput("NewIris")),
tabPanel("NewPetrolTab",
DT::dataTableOutput("NewPetrol"))
)
)
)
))
Run Code Online (Sandbox Code Playgroud)
shinyServer(function(input,output){
output$OldIris <- DT::renderDataTable({
datatable(iris,editable=T)
})
output$OldPetrol <- DT::renderDataTable({
datatable(petrol,editable=T)
})
######
# HERES WHERE I'M NOT REALLY SURE WHAT TO DO
change_data1 <- eventReactive(input$runButton, {
withProgress(message="Generating new dataframes",{
newdf1 <- datatable(output$OldIris)
newdf1
})
})
change_data2 <- eventReactive(input$runButton, {
withProgress(message="Generating new dataframes",{
newdf2 <- datatable(output$OldPetrol)
newdf1
})
})
output$NewIris <- DT::renderDataTable({
datatable(change_data1())
})
output$NewPetrol <- DT::renderDataTable({ …Run Code Online (Sandbox Code Playgroud) 我已经gcsfs在我的云功能中使用了一段时间,没有出现任何问题。突然,它停止了新部署的功能,并抛出错误:(
RuntimeError: This class is not fork-safe照片中附有完整的回溯)
我猜这是由于包的依赖项之一造成的gcsfs。无论如何,我已经更新gcsfs到当前版本,但这requirements.txt没有帮助。
可以通过如下定义云函数来重现该错误(Python 3.7):
主要.py:
import gcsfs
# Read in runners and races for end_date
fs = gcsfs.GCSFileSystem(project='project-name-1234')
def try_gcsfs(request):
with fs.open(r'any_csv_file_in_cloud_bucket.csv', 'rb') as f:
lines = []
for line in f:
lines.append(line.decode(errors='ignore'))
print('success')
Run Code Online (Sandbox Code Playgroud)
要求.txt:
gcsfs==2021.10.0
Run Code Online (Sandbox Code Playgroud)
df <- data.frame(category=c("cat1","cat1","cat2","cat1","cat2","cat2","cat1","cat2"),
value=c(NA,2,3,4,5,NA,7,8))
Run Code Online (Sandbox Code Playgroud)
我想在上面的数据框中添加一个新列,它采用value列的累积平均值,而不考虑 NA。有可能做到这一点dplyr吗?我试过了
df <- df %>% group_by(category) %>% mutate(new_col=cummean(value))
Run Code Online (Sandbox Code Playgroud)
但cummean就是不知道如何处理 NA。
编辑:我不想将 NA 计为 0。
r ×3
python ×2
dplyr ×1
dt ×1
keras ×1
outlook ×1
pipeline ×1
rdcomclient ×1
scikit-learn ×1
shiny ×1
tensorflow ×1