K-means error in foreign function call - rstudio

I am trying to do the clustering on a set of data using the easy:
fit <- kmeans(my data, 2)
The problem is, when I run it, I get:
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message: In kmeans(my data, 2) : NAs introduced
by coercion
Even though I checked whether I had only numbers in the data set.
Any ideas what might be wrong?

First, can you do str(my data)? Second, don't use a space in the name.
Maybe you have numeric id columns.
Please see link 1 and link 2.

Related

Odoo 8 "message_id" column in "mail_message" table

I was writing an external app in python that uses the message system in odoo.
So, I need to use, the mail_message, and the mail_notification tables.
I tried to put elements individually via INSERT into the table filling the necessary elements to make this work, and it works perfectly, the messages appear in the "inbox" of messages in Odoo and the notification appears correctly.
But checking the rest of the fields in this table, I see that message_id got a tag format (between <>) and a series of numbers (that I haven't found any correlation) followed by "-openerp-'res_id'-'model'-#'company'".
So, I don't know how to fill this field, my proofs determined that is not a necessary field, but in a serious implementation I don't know if left this field empty can cause some issues.
Anyone can explain me the reason of this field and how to fill it?
Thanks
You can check the code in tools/mail.py and do something similar
def generate_tracking_message_id(res_id):
"""Returns a string that can be used in the Message-ID RFC822 header field
Used to track the replies related to a given object thanks to the "In-Reply-To"
or "References" fields that Mail User Agents will set.
"""
try:
rnd = random.SystemRandom().random()
except NotImplementedError:
rnd = random.random()
rndstr = ("%.15f" % rnd)[2:]
return "<%.15f.%s-openerp-%s#%s>" % (time.time(), rndstr, res_id, socket.gethostname())

How to skip run time error in tibco?

I am new to tibco and I am working on tibco BW 5.X versions.
I have a scenario where I am working on multiple records coming in from a schema and I have to write a text file with only specific values out of those records.
Ex :
if this is the input:
<param>1</param>
<param>2</param>
<param>1</param>
<param>1</param>
I only have to write the param having values 1 and have to generate error for param having values 2 but after generating error the iteration that is currently going on should continue and must not stop.
I would be grateful if someone can help
I assume in case of the value "2" you want to invoke the "Generate Error" Activity to throw an error up to a calling process or client that some entry was not correct, right?
So if you want to make sure to process the whole list you should not throw the error in the loop group on the list as it will exit.
You can either:
Use 2 seperated lists
map the entries with value "1" into a good list that enter the loop and entries with value "2" into a bad list, that will if filled let you then invoke the "Generate Error" activity after the loop processing.
Append the entries with value "2" in your loop
Thereby after processing the loop you have these entries and if the list contains entries invoke the "Generate Error" activity.
Hope that helps
Cheers Seb
P.s.: if you upload your process it would be more clear to show ;)
You could create a output schema which contains only param1 values and use a mapper activity to perform corresponding transformation and xpath functions for filtering. If you try to implement this solution you can eliminate the chance of param2 values creeping into your output.

why does sorting a table in Lua doesn't work

I have a piece of Lua code that generate an error and I don't understand how to solve it.
.............................
local last_num = 0
local channelTable={}
for num in channels.each_number() do -- channels.each_number() returns 1.number in each call
channelTable[last_num] =num;
last_num = last_num +1;
end
table.sort(channelTable);
based on lua documentation I can use the function sort to sort the saved numbers in channelTable. the error that I get is:
attempt to index global 'table'
Any idea how can I solve this, or should implement bubble sort?
thanks for any hint!
Either you haven't loaded the table library or you have overwritten it by accident.
The error message seems truncated: it should say why indexing failed.
The error you are seeing indicates that the table library is not available. It's unlikely that this core library isn't part of your Lua environment, so it's likely you have assigned something to table elsewhere in your code.
I think the issue may be that you are expecting channels.each_number() to be called in each iteration of the loop. If I'm not mistaken, I think it only gets called the first time the program goes through the loop. Whatever you use in thefor..in loop needs to be a table, I believe. So I guess the problem is that your table isn't being generated as you want it to. Try doing this:
print('number of items in channelTable = ' .. #channelTable)
If it comes out to 0, then what I said is probably the problem.

Type mismatch error while reading lotus notes document in vb6

Am trying to read the lotus notes document using VB6.I can able to read the values of the but suddenly type mismatch error is throwed.When i reintialise the vb6 variable it works but stops after certain point.
ex; address field in lotus notes
lsaddress=ImsField(doc.address)
private function ImsField(pValue)
ImsField=pValue(0)
end function
Like this I am reading the remaining fields but at certain point the runtime error "13" type mismatch error throwed.
I have to manually reintialize by
set doc=view.getdocumentbykey(doclist)
The type mismatch error occurs for a certain field. The issue should be a data type incompatibility. Try to figure out which field causes the error.
Use GetItemValue() instead of short notation for accessing fields and don't use ImsField():
lsaddress=doc.GetItemValue("address")(0)
The type mismatch is occurring because you are encountering a case where pValue is not an array. That will occur when you attempt to reference a NotesItem that does not exist. I.e., doc.MissingItem.
You should not use the shorthand notation doc.itemName. It is convenient, but it leads to sloppy coding. You should use getItemValue as everyone else is suggesting, and also you should check to see if the NotesItem exists. I.e.,
if doc.hasItem("myItem") then
lsaddress=doc.getItemValue("myItem")(0)
end if
Notes and Domino are schema-less. There are no data integrity checks other than what you write yourself. You may think that the item always has to be there, but the truth is that there is nothing that will ever guarantee that, so it is always up to you to write your code so that it doesn't assume anything.
BTW: There are other checks that you might want to perform besides just whether or not the field exists. You might want to check the field's type as well, but to do that requires going one more level up the object chain and using getFirstItem instead of getItemValue, which I'm not going to get into here. And the reason, once again, is that Notes and Domino are schema-less. You might think that a given item must always be a text list, but all it takes is someone writing sloppy code in an one-time fix-it agent and you could end up having a document in which that item is numeric!
Checking your fields is actually a good reason (sometimes) to encapsulate your field access in a function, much like the way you have attempted to do. The reason I added "sometimes" above is that your code's behavior for a missing field isn't necessarily always going to be the same, but for cases where you just want to return a default value when the field doesn't exist you can use something like this:
lsaddress ImsField("address","")
private function ImsField(fieldName,defaultValue)
if doc.hasItem(fieldName) then
lsaddress=doc.getItemValue(fieldName)(0)
else
lsaddress=defaultValue
end if
end function
Type mismatch comes,
When you try to set values from one kind of datatype variable to different datatype of another variable.
Eg:-
dim x as String
Dim z as variant
z= Split("Test:XXX",":")
x=z
The above will through the error what you mentioned.
So check the below code...
lsaddress = ImsField(doc.address)
What is the datatype of lsaddress?
What is the return type of ImsField(doc.address)?
If the above function parameter is a string, then you should pass the parameter like (doc.address(0))

Excel UDF returns a huge number

Excel AddIn using Excel DNA, VS2008, C#,
MyUDF(param1, parm2)
when I type in "=MyUDF" and hit enter, Excel displays a huge number like 970063926
and my c# code for MyUDF is not run
Anyone know what is this huge number?
thanks
This is just a bit of weird behaviour of Excel. The number being returned is an internal identifier for the UDF function, and by entering the function name without any brackets, you're causing it to be treated like a named range not a function. If you want to call the function with no arguments, use:
=MyUDF()
...if you type =MyUDF then you're asking Excel to dereference the function name, in the same way that it would dereference =A1 to the value in cell A1 or =MyNamedRange to whatever that named range referred to.
I don't think there's any practical use for the behaviour you've observed, but it certainly isn't going anywhere near your code to get this value that is being returned, so don't worry you haven't done anything wrong!
Is there any way to avoid this behavior?
If no parameter is specified, I would like the =MyUDF to return error instead a number.

Resources