I have got a problem with reading my shapefile. The below code used to work properly but all of a sudden I got the below error. I reinstalled R, Rstudio, and all the related packages but none of them fixed the problem.
Thanks,
NM
usshapefile <- "cb_2017_us_county_500k.shp"
usgeo <- read_shape(file=usshapefile, as.sf = TRUE)
Error in read_shape(file = usshapefile, as.sf = TRUE) :
could not find function "read_shape"
It looks like read_shape() is a function from an older version of tmap.
If you want an sf object from a shapefile, try using read_sf() from the sf package.
library(sf)
usshapefile <- "cb_2017_us_county_500k.shp"
usgeo <- read_sf(file=usshapefile)
If you've already updated your packages, you might want take a look at the reference pages for their respective functions too.
sf reference
tmap functions pdf
tmap reference
Related
I am new to deep learning and trying to implement code written here
http://r2rt.com/recurrent-neural-networks-in-tensorflow-i.html.
I am trying to implement same code but I am getting error
no module name basic_rnn
while importing basic_rnn as written in the code:
import basic_rnn
def plot_learning_curve(num_steps, state_size=4, epochs=1):
global losses, total_loss, final_state, train_step, x, y, init_state
tf.reset_default_graph()
g = tf.get_default_graph()
losses, total_loss, final_state, train_step, x, y, init_state = \
basic_rnn.setup_graph(g,basic_rnn.RNN_config(num_steps=num_steps, state_size=state_size))
res = train_network(epochs, num_steps, state_size=state_size, verbose=False)
plt.plot(res)
then I changed basic_rnn = tf.contrib.rnn.BasicRNNCell,
then I am getting error
'module' object has no attribute 'setup_graph'.
I am assuming I will again get error in while implementing basic_rnn.RNN_config.
What would be the correct syntax?
I am using tensorflow of version 1.0.0
pls help
You can look at the gist code provided by the author, r2rt:
https://gist.github.com/anonymous/5fc9903990ecec5f09361934920bb999. Though you need to tweak the code a bit to get it run.
Basically, you need to implement the setuo_graph and RNN_config functions in basic_rnn.py. But since there are three versions of RNNs that the original blog is comparing, I think it would be better if you put RNN_config in one Python file.
Besides, I found some of r2rt's code is deprecated, so I adapted the code and created my own repo. Check it out if you are interested:
https://github.com/innerfirexy/rnn-tf-r2rt
You can run the code in run_RNNs.py in IPython. I changed the gist code a bit by moving the RNN_config function to train.py, and giving train_network a config parameter.
I have a piece of code as follows:
Poco::JSON::Parser a;
Poco::Dynamic::Var v = a.parse(str); //str is a json string
Poco::JSON::Object::Ptr p = v.extract<Poco::JSON::Object::Ptr>();
p->set("key","value");
in Poco v 1.6.0 this works completely fine, and the content of v is changed according to the set function, yet in 1.6.1 it's not working anymore, is there a difference on the set function call between 1.6.0 and 1.6.1? Or what could be the potential problem? (My current observation is that in 1.6.1 the set line is not executed at all.)
Thank you for reading this.
Note: If there's any work around that can achieve the same effect but doesn't have to use the set function I'll be appreciated.
So I find out the answer today and decided to share with people.
Answer: the set() function Poco::JSON::Object is different in 1.6.0 and 1.6.1. In 1.6.1 it will not function if there's already value assigned to that give key, while in 1.6.0 it will just overwrite it. A very simple work around for 1.6.1 is you can first do remove() function then do the set() function, then it will work the same. But yes, the implementation is different and can be checked in the source code of the Poco library.
I am facing a weird error within my codebase currently. You can see the full ZF2s project code on my github right here. <- there's a link
I'm having a Module set up with two Entities (X and Y). Entity_X contains a reference to Entity_Y via (targetEntity="Entity_Y"). The Error persist with the FQCN or just the CN itself.
Entity_X:
id int PK,
id_Y int FK,
text varchar
Entity_Y:
id int PK,
text varchar
When loading Entity_Y first and then Entity_X everything is working fine. This remains true for both StandardAutoloader and ClassMapAutoloader. However: when loading Entity_X first with ClassMapAutoloader present, i will be seeing the following error:
Fatal error: Cannot redeclare class Kennzahlen\Entity\Referenzwert (Entity_Y)
in \module\Kennzahlen\src\Kennzahlen\Entity\Referenzwert.php
on line 13
Loading Entity_X first with StandardAutoloader works without any problems, too.
Update
The Problem appears to be within ZF2s ClassMapAutoloader (or Autoloading-Mechanism in General). My Module used the ClassMapAutoloader and using this i've gotten the above mentioned error. When removing the ClassMapAutoloader and simply using the StandardAutoloader, the error vanished into thin air. Thanks to #ocramius and all others i've botheres with this :)
I'm writing a failing test case to try and solve this in doctrine/common. The problem seems to be that silent autoloaders (as explained by #Xerkus) are not compatible with doctrine/common itself. To solve that, use a StandardAutoloader from ZF2 (or from composer) instead of using the ClassMapAutoloader. This will solve the issue until a patch is ready.
Update: patch is being suggested at doctrine/common#216
i have no knowledge of doctrine, but i browsed through source and i think i found issue:
https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/ClassLoader.php#L224
here, this code expects that autoloader will return value evaluated to true, but that is not requirement of spl autoload mechanism, therefore autoloader can return NULL,
To check if i am correct, in in your project in doctrine replace line 224 in Doctrine/Common/ClassLoader.php
} else if ($loader[0]->{$loader[1]}($className)) {
with
} else if ($loader[0]->{$loader[1]}($className) && class_exists($className, false)) {
Ans see if issue is fixed, if i am correct - then report bug to doctrine project
I'm writing a unit test in R, which needs to read some test data defined in the same directory. But I would also like to be able to run that unit test no matter what the current working directory happens to be.
Is there a way to tell R to load a file from here, where here is defined as the directory holding the source file of the function being executed?
Depends on how what you mean with "I'm writing a unit test". If you just source that function from wherever, David is right and I don't even see the need to do that as you know which directory it is.
I would include that function in a package, and then there are mechanisms in R allowing you to make the data available for loading or via lazy-loading. See section 1.1.5 (Data in packages) in the manual Writing R Extensions. This is the R-way of doing it.
Another option Gabor Grothendieck gave in this thread on the R mailing list, is to add following line at the top of a script :
this.dir <- dirname(parent.frame(2)$ofile)
This will give the directory of the file when sourced using source(). Gabor calls it a dirty hack, and I agree with him.
On a sidenote, check also following packages for unit testing in R :
RUnit
svUnit
testthat
If the functions aren't in a package, and sourced from files via source() then perhaps source references might provide something to work with. Argument keep.source = TRUE is required, and read the R Journal article by Duncan Murdoch
Here is a quick example:
> setwd("./Downloads/")
> source("../foo.R", keep.source=TRUE) ## if options("keep.source") is FALSE
> bar
function(a, b) {
a + b
}
> body(bar)
{
a + b
}
attr(,"srcfile")
../foo.R
attr(,"wholeSrcref")
bar <- function(a, b) {
a + b
}
> srcref <- attr(body(bar), "srcref")[[1]]
> attr(srcref, "srcfile")
../foo.R
> ls(attr(srcref, "srcfile"))
[1] "Enc" "encoding" "filename" "timestamp" "wd"
> attr(srcref, "srcfile")$filename
[1] "../foo.R"
> attr(srcref, "srcfile")$wd
[1] "/home/gavin/Downloads"
Of course this assumes you don't know where the sourced functions come from to be of any use and yet the functions need to be sourced...
If this is in a package, then you can have data in a ./data directory or arbitrary directories in ./inst/. You can use data() toload datasets from the former, and system.file() for any file in a package. See the relevant help pages.
There's no realistic hope of achieving this in full generality. Functions don't need to be loaded from files, they can be created dynamically by code, loaded from workspaces and so on.
I know that all forums are full of such question, but I've tried few hooks, and they doesn't work (or I do them bad).
So, I've got:
main.cpp <- fawn.h <- connector.cpp (defenition) <- conncetor.h (declaration)
<- portl.cpp (def) <- portl.h (dcl) <- connector.h
with include guard (thanks to Igor Zevaka and jk), everything compiles, but doesn't link,
saying "already defined in main.obj" about all funcs., no metter are they static or not.
I've tryed already pulling the conncetor.h contents to connector.cpp, same way with portl.cpp (there was #include "connector.h" in it).
Thanks beforehand.
Does fawn.h include connector.cpp? (or do I read it wrong?)
If so this is your error. Now connector.cpp (itself) has a function bla() and main.cpp has same function because it includes (read: copy-pasted in) connector.cpp. And you are trying to link them together.
EDIT:
For the last error make sure FAWN::Sys::Connecter::getSocket(void) is implemented somewhere (and that cpp file it is in is linked in). Looks like it is just missing.
Make sure that you link properly against the required libraries of boost...
Check the dependencies here:
http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/using.html