在2013年6月1日,我预计"PST8PDT"时区的行为与GMT + 7一样,因为它是该时区的夏令时.但是,它的行为类似于GMT + 8:
>>> import pytz, datetime
>>> Pacific = pytz.timezone("PST8PDT")
>>> datetime.datetime(2013, 6, 1, 12, tzinfo=Pacific).astimezone(pytz.utc)
datetime.datetime(2013, 6, 1, 20, 0, tzinfo=<UTC>)
Run Code Online (Sandbox Code Playgroud)
相比之下,在2013年1月1日,它表现得(正确)像GMT + 8:
>>> datetime.datetime(2013, 1, 1, 12, tzinfo=Pacific).astimezone(pytz.utc)
datetime.datetime(2013, 1, 1, 20, 0, tzinfo=<UTC>)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?提前致谢!
我正在开发一个提供名为"Foo"的S3类的包.它还提供了一种"as"方法,用于将其强制转换为名为"Bar"的(其他人)S4类.我的代码看起来像这样:
#' ...
setOldClass("Foo")
#' ...
setAs("Foo", "SpatialPointsDataFrame", function(from) {
# do stuff and return a SpatialPointsDataFrame
})
Run Code Online (Sandbox Code Playgroud)
编辑我试过这个:
#' ...
#' @name as
#' @export
setAs("Foo", "SpatialPointsDataFrame", function(from) {
# do stuff and return a SpatialPointsDataFrame
})
Run Code Online (Sandbox Code Playgroud)
但是我从R CMD检查得到这个:
检查是否可以使用声明的依赖项加载名称空间...警告namespaceExport(ns,exports)中的错误:undefined exports:as Calls:loadNamespace - > namespaceExport Execution halted
命名空间必须只能加载基础命名空间:否则如果命名空间被保存的对象加载,则会话将无法启动.
可能需要在NAMESPACE文件中声明一些导入.
在一个单独的.R文件中,我有:
#' @importClassesFrom sp SpatialPointsDataFrame
Run Code Online (Sandbox Code Playgroud)
我正在使用hadley的devtools包,所以我猜它是roxygen2.这就是我做的:
R> document("MyPackage")
Run Code Online (Sandbox Code Playgroud) 我有一个R/ ggplot2用例似乎需要geom_raster:一个常规的笛卡尔网格,在x,y位置有z值.我一直在使用geom_tile,我期望从切换到性能改进geom_raster.但我似乎没有看到一个......
这是一个玩具示例(但大小合适),使用base图形:
n <- m <- 200
x <- 1:n
y <- 1:m
f <- function(x, y) 10 * sin(x / n) * cos(y / m)
z <- outer(x, y, f)
system.time(image(z))
user system elapsed
0.998 0.007 1.023
Run Code Online (Sandbox Code Playgroud)
这是ggplot2:
obs <- expand.grid(x=x, y=y)
obs$z <- as.numeric(as.list(z))
require(ggplot2)
p <- ggplot(obs, aes(x=x, y=y, fill=z))
system.time(show(p + geom_tile()))
user system elapsed
7.328 0.891 8.187
require(ggExtra)
system.time(show(p + geom_raster())) …Run Code Online (Sandbox Code Playgroud) 将ggvis图形导出为PNG文件(包含在.Rmd文档中).
我基本上对Node.js一无所知,除了它很棒,我应该知道更多.
我得到:
library(ggvis)
mtcars %>% ggvis(~mpg, ~wt) %>% export_png()
Writing to file plot.png
Guessing layer_points()
module.js:340
throw err;
^
Error: Cannot find module 'd3'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/usr/local/src/vega/index.js:11:6)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Run Code Online (Sandbox Code Playgroud)
devtools::install_github("hadley/ggvis")安装ggvis(0.3.0.9001)和依赖项https://github.com/trifacta/vega到/usr/local/src/vega./bin/vg2png -> /usr/local/src/vega/bin/vg2pngsessionInfo() …Run Code Online (Sandbox Code Playgroud) 这是一个简单的分类法(标签和ID):
test_data <- data.frame(
cat_id = c(661, 197, 228, 650, 126, 912, 949, 428),
cat_h1 = c(rep("Animals", 5), rep("Plants", 3)),
cat_h2 = c(rep("Mammals", 3), rep("Birds", 2), c("Wheat", "Grass", "Other")),
cat_h3 = c("Dogs", "Dogs", "Other", "Hawks", "Other", rep(NA, 3)),
cat_h4 = c("Big", "Little", rep(NA, 6)))
Run Code Online (Sandbox Code Playgroud)
解析后的结构应与以下内容匹配:
list(
Animals = list(Mammals = list(Dogs = list(Big = 661, Little = 197), Other = 228),
Birds = list(Hawks = 650, Other = 126)),
Plants = list(Wheat = 912, Grass = 949, Other = 428))
Run Code Online (Sandbox Code Playgroud)