global-variables

How to use acast (reshape2) within a function in R?

浪尽此生 提交于 2019-12-20 23:19:06
问题 I tried to use acast from reshape2 within a self written function, but had the problem that acast did not find the data I send to it. Here is my data: library("reshape2") x <- data.frame(1:3, rnorm(3), rnorm(3), rnorm(3)) colnames(x) <- c("id", "var1", "var2", "var3") y <-melt(x, id = "id", measure = c("var1", "var2", "var3")) y then looks like this: id variable value 1 1 var1 0.1560812 2 2 var1 1.0343844 3 3 var1 -1.4157728 4 1 var2 0.8808935 5 2 var2 0.1719239 6 3 var2 0.6723758 7 1 var3 -0

What does “global variables are bad” mean?

瘦欲@ 提交于 2019-12-20 14:40:06
问题 So I can read from a global variable def f() : print x And I can also assign it def g() global x x = 3 When people say "global variables are bad", do they mean that both reading and assigning are bad, or just assigning is bad? (my impression is that reading is not dangerous) 回答1: The problem is not so much "global == bad" so much as "Global mutable state makes it hard to reason about program flow" To illustrate, imagine this function: def frob(): if my_global: wibble() else: wobble() That is,

Why are local variables accessed faster than global variables in lua?

冷暖自知 提交于 2019-12-20 12:07:16
问题 So I was reading Programing in Lua 2nd Ed and I came across this paragraph here: It is good programming style to use local variables whenever possible. Local variables help you avoid cluttering the global environment with unnecessary names. Moreover, the access to local variables is faster than to global ones . Could anyone explain why this is? And is this "feature" only in Lua, or is it in other languages aswell? (e.g. C, C++, Java) 回答1: The difference in running time is due to the

Sharing objects and avoiding globals in node.js

会有一股神秘感。 提交于 2019-12-20 10:27:12
问题 What would be the most appropriate way of sharing the database connection in the below snippet ( the db variable) with my routers/controllers without turning the db variable into a global? var mongo = require('mongoskin'), db = mongo.db(config.db.adress); app.use(function(req, res, next) { db.open(function(err, data) { (err) ? res.send('Internal server error', 500) : next(); }); }); // Setting up controllers here app.post('/users', require('./controllers/users').create); Coming from a PHP

How to get current role name in an ansible task

本小妞迷上赌 提交于 2019-12-20 10:01:11
问题 How can I get the current role name in an ansible task yaml file? I would like to do something like this --- # role/some-role-name/tasks/main.yml - name: Create a directory which is called like the current role name action: file path=/tmp/"{{ role_name }}" mode=0755 state=directory The result of this task should be a directory /tmp/some-role-name on the server 回答1: As of Ansible 2.2 : {{role_name}} As of Ansible 2.1 : {{role_path|basename}} Older versions: There is no way to do this in the

How to get current role name in an ansible task

一曲冷凌霜 提交于 2019-12-20 10:01:10
问题 How can I get the current role name in an ansible task yaml file? I would like to do something like this --- # role/some-role-name/tasks/main.yml - name: Create a directory which is called like the current role name action: file path=/tmp/"{{ role_name }}" mode=0755 state=directory The result of this task should be a directory /tmp/some-role-name on the server 回答1: As of Ansible 2.2 : {{role_name}} As of Ansible 2.1 : {{role_path|basename}} Older versions: There is no way to do this in the

CodeIgniter: global variables in a controller

人走茶凉 提交于 2019-12-20 09:36:16
问题 I'm a very newbie on CodeIgniter, and while I go on I run into problems that, in the procedural coding, were easy to fix The current issue is: I have this controller class Basic extends Controller { function index(){ $data['title'] = 'Page Title'; $data['robots'] = 'noindex,nofollow'; $data['css'] = $this->config->item('css'); $data['my_data'] = 'Some chunk of text'; $this->load->view('basic_view', $data); } function form(){ $data['title'] = 'Page Title'; $data['robots'] = 'noindex,nofollow';

Error Global Variable not defined when importing class

冷暖自知 提交于 2019-12-20 07:33:23
问题 I am trying to implement a movement system where the player move's towards the click position. But I have been running into some problems with the arguments of the movement method. The movement method currently needs to take all the variables as arguments: This code works: def move(self,event,mouse_pos, screen, background): if event.type == MOUSEBUTTONDOWN: if mouse_pos[1] > self.pos[1]: screen.blit(background, self.pos, self.pos) #erases players by bliting bg self.speed = 1 self.move_south()

Android - Global variables?

烂漫一生 提交于 2019-12-20 07:27:04
问题 I need to stock some datas in my application. I know that i can do it like this: class: public class MyApplication extends Application { private String someVariable; public String getSomeVariable() { return someVariable; } public void setSomeVariable(String someVariable) { this.someVariable = someVariable; } } Implementation: MyApp appState = ((MyApp)getApplicationContext()); String state = appState.getSomeVariable(); This is working if i'm in an activity. But if i'm in a class not extended

PHP: How to make variable visible in create_function()?

社会主义新天地 提交于 2019-12-20 07:12:57
问题 This code: $t = 100; $str = preg_replace_callback("/(Name[A-Z]+[0-9]*)/", create_function( '$matches', 'return $matches[1] + $t;' ), $func); How to make $t visible from create_function() in preg_replace() function? 回答1: An anonymous function would work, while making use of the use syntax: $t = 100; $str = preg_replace_callback("/(Name[A-Z]+[0-9]*)/", function($matches) use($t) // $t will now be visible inside of the function { return $matches[1] + $t; }, $func); 回答2: You can't make the