在阅读http://ggvis.rstudio.com/interactivity.html时,我注意到代码中有:=洒在其中.我假设这是一种为函数提供参数的新方法?究竟是什么?
mtcars %>%
ggvis(~wt, ~mpg, size := input_slider(10, 1000)) %>%
layer_points(fill := "red") %>%
layer_points(stroke := "black", fill := NA)
Run Code Online (Sandbox Code Playgroud) 使用数据框时,通常需要一个子集.但是不鼓励使用子集函数.以下代码的问题是数据框名称重复两次.如果你复制并粘贴和munge代码,很容易不会意外地改变第二次提到的adf,这可能是一场灾难.
adf=data.frame(a=1:10,b=11:20)
print(adf[which(adf$a>5),]) ##alas, adf mentioned twice
print(with(adf,adf[{a>5},])) ##alas, adf mentioned twice
print(subset(adf,a>5)) ##alas, not supposed to use subset
Run Code Online (Sandbox Code Playgroud)
有没有办法在不提及adf两次的情况下编写上述内容?不幸的是,使用with()或within(),我似乎无法访问整个adf?
子集(...)函数可以很容易,但他们警告不要使用它:
这是一种便于交互使用的便利功能.对于编程,最好使用像[的标准子集函数,特别是参数子集的非标准评估可能会产生意想不到的后果.
如何在 Jupyter 中运行 R 中的 %%magic?
%%javascript
IPython.OutputArea.auto_scroll_threshold = 99999;
Run Code Online (Sandbox Code Playgroud)
较长输出的自动滚动功能非常烦人,因为我有几个函数和脚本会输出大量输出。
上面的 Javascript 在 python 笔记本中运行良好,但在 R 笔记本中则不行。
当我在 R 中运行 %% magic 命令时,它会吐出:
Error in parse(text = x, srcfile = src): <text>:1:1: unexpected SPECIAL
1: %%
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
根据这篇文章disable_autoscroll.py,可以将该Javascript放入profile_dir/static/js/custom.js文件中。请告诉我,Windows 机器上的 profile_dir 在哪里?
我发现:c:/Anaconda2/Lib/site-packages/notebook/static/custom/custom.js但那是中心的 custom.js 文件。
参考:
以下是完全伪造的代码.但是,假设你需要做一些额外的副作用函数调用(用于调试日志)?你怎么把它放进去的?
[ i for i in range(10) ]
Run Code Online (Sandbox Code Playgroud)
或者总是必须重写为正常的循环?
list=[]
for i in range(10):
otherStuff()
list.append(i)
Run Code Online (Sandbox Code Playgroud)
在C中,有一个逗号运算符用于此类事情......
哪个人得到jsonlite?CRAN显然缺少它?
> install.packages('jsonlite')
Run Code Online (Sandbox Code Playgroud)
得到:
Installing package into ‘C:/Users/cbusch/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/jsonlite_0.9.20.zip'
Warning in install.packages :
cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/jsonlite_0.9.20.zip': HTTP status was '404 Not Found'
Error in download.file(url, destfile, method, mode = "wb", ...) :
cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/jsonlite_0.9.20.zip'
Warning in install.packages :
download of package ‘jsonlite’ failed
Run Code Online (Sandbox Code Playgroud)
有什么建议?
为什么不采用绿色?它保持蓝色......
require(ggplot2)
data(iris)
ggplot(iris,aes(Sepal.Length,Sepal.Width,col=Petal.Length,pch=Species,size=Petal.Width))+
scale_fill_gradient(low="green",high="darkgreen")+
ggtitle('Why so blue?')+geom_point()
Run Code Online (Sandbox Code Playgroud)
有什么建议?