我想查看包含任何注释的R源代码,以查看包的作者如何运行他的代码,但我不确定使用什么命令来查看它.特别是,我试图bgp()在R tgp包中看到该函数的源代码.到目前为止我已经尝试过
library(tgp)
tgp::bgp
tgp:::bgp
Run Code Online (Sandbox Code Playgroud)
但是这些命令中的每一个都只显示剥离了注释的源代码.
请考虑以下字符串:
to_run = "alpha = data.frame(a=1:3, b=2:4)"
Run Code Online (Sandbox Code Playgroud)
要么
to_run = "for (i in 1:10){print(i);print('Hello World!')}"
Run Code Online (Sandbox Code Playgroud)
如何运行在对象中写为字符串字符的代码to_run?
一种解决方案是在外部文件上输出对象并获取它:
write.table(to_run, 'I.am.a.Path/folder/file.name', quote=F, row.names=F, col.names=F)
source('I.am.a.Path/folder/file.name')
Run Code Online (Sandbox Code Playgroud)
还有另一种更直接的解决方案吗?
我正在尝试将装饰器编写到现有的类中,如果没有足够的可用资源则拒绝该类.这是一个没有多线程的代码示例版本:
public interface Handler {
boolean handleTask(Task myTask); // returns true if successful, false if failure
}
public interface Task {
int getResources();
// Among other things
}
public BlockingHandler implements Handler {
private int occupied;
private final int limit;
private final Handler backingHandler;
BlockingHandler(Handler backingHandler) {
this.backingHandler = backingHandler;
}
@Override
public boolean handleTask(Task myTask) {
if(myTask.getResources() + occupied > limit) return false;
occupied += myTask.getResources();
return backingHandler.handleTask(myTask);
}
// Don't worry about this part, I'm not doing it …Run Code Online (Sandbox Code Playgroud) 出于好奇,我在mscorlib/system/collections/generic/comparer.cs中查看了抽象的Comparer(T)类源代码,并且发现我发布的源代码中缺少构造函数.知道为什么吗?
从 BASH 页面:
当使用 source 运行脚本时,它在现有 shell 中运行,脚本创建或修改的任何变量在脚本完成后仍然可用。相反,如果脚本仅作为文件名运行,则将生成一个单独的子 shell(具有一组完全独立的变量)来运行该脚本。
但如果我跑步会发生什么
. myscript &
Run Code Online (Sandbox Code Playgroud)
在这种情况下它作为子 shell 运行吗?. myscript &和 和有什么区别./myscript &?
假设你有像这样的唯一数字
11,2,7,6,17,13,8,9,3,5,12
Run Code Online (Sandbox Code Playgroud)
结果将是包含子列表的数字组列表,即,
[2,3]-[5,6,7,8,9]-[11,12,13]-[17]
Run Code Online (Sandbox Code Playgroud)
我采用这种方法来解决这个问题:
int[] a = { 11, 2, 7, 6, 13,17, 8, 9, 3, 5, 12 };
Arrays.sort(a);
List<List<Integer>> ListMain = new ArrayList<>();
List<Integer> temp = new ArrayList<>();
for (int i = 0; i < a.length; i++) {
if (a[i + 1] == a[i] + 1) {
temp.add(a[i + 1]);
} else {
ListMain.add(temp);
temp.clear();
}
}
Run Code Online (Sandbox Code Playgroud) 我已经使用hashCode()了StringAPI的方法,它为以下代码生成的值为99162322:
String str = "hello";
System.out.println(str.hashCode());
Run Code Online (Sandbox Code Playgroud)
是否有任何Java API可以生成仅5位数字(63346)的哈希值,例如下面的Oracle SQL?
select ORA_HASH('hello','99999') from dual --63346
Run Code Online (Sandbox Code Playgroud) 我有一个名为52bbb58c的文件,没有文件扩展名,它是mp4视频。
当我尝试将其添加为&<source>到<video>与属性类型(视频/ MP4),它不能播放。
这适用于Chrome和Firefox。如何为Safari修复它?
在 Gson 文档中,我遇到了这个构造,用于将 JSON 化的 Spotify Artist 对象列表转换回对象的 ArrayList。我在 onRestoreInstanceState() 中使用它。
但是,我从未见过声明后的 {}。有人能给我解释一下这是什么意思吗?我知道 getType() 是一个成员类,但为什么是 {}?
Type type = new TypeToken<List<Artist>>() {}.getType();
mArtistsList = new Gson().fromJson(jsonSearchResults, type);
Run Code Online (Sandbox Code Playgroud) 有一个类Company,它引用了另一个Company表示的实例parent.比方说,有四家公司c1,c2,c3和c4和c2,c3,c4有母公司设置c1.
例如:
public class Company {
public Company parent;
public Company() { }
public Company(Company parent) {
this.parent = parent;
}
public static void main(String[] args) {
Company c1 = new Company();
Company c2 = new Company(c1);
Company c3 = new Company(c1);
Company c4 = new Company(c1);
}
Run Code Online (Sandbox Code Playgroud)
如果我们设置c2为以下的母公司c1:
c1.parent = c2;
Run Code Online (Sandbox Code Playgroud)
然后它将在公司层次结构中创建一个Cyclomatic …