r - Windows下用R发送通知
问题描述
我目前正在使用 R 语言记录/更新我在银行中的表格:
dbWriteTable (with," table ", table, row.names = FALSE, overwrite = TRUE)
我的这个脚本更新了 postgres 数据库中 R 中的表,由 windows 任务不时自动运行。
我需要知道何时记录了信息,可能是屏幕上的警报格式,或者是什么吸引眼球的东西。
注意:我知道有“r.out”,但它会覆盖,当问题发生时不会发出警告,或者类似的东西。
解决方案
您可以调用 Windows Powershell:
- 运行 powershell 并授权脚本执行:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
- 创建一个通知脚本并执行它
system
:
showMessage <- function(message) {
MessageScript <-'
[CmdletBinding()]
$ErrorActionPreference = "Stop"
$notificationTitle = "{message}"
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
#Convert to .NET type for XML manipuration
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
#Convert back to WinRT type
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.Tag = "PowerShell"
$toast.Group = "PowerShell"
$toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(5)
#$toast.SuppressPopup = $true
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell")
$notifier.Show($toast);'
system('powershell',input=glue::glue(MessageScript),show.output.on.console=F)
}
showMessage(message = 'this is a test')
推荐阅读
- memory - 使用 4*8k 内存单元构建 4*32k 内存
- javascript - querySelector() 只给一个类而不是多个
- bash - 由 <() 技巧引起的意外标记 `(' 附近的 bash 语法错误
- ios - 如何在 ios 中使用 expo sdk 42 管理发出严重警报
- java - 代理对的 XML 编组
- unreal-engine4 - 减小导航网格边界大小
- r - 什么函数可以中断正在运行的 R 脚本?
- python - 框架中的 tkinter 垂直滚动条不是框架无法正常工作
- kendo-ui - Kendo mvc 网格插入了带有自定义类的新行
- c# - 使用返回的实例?