using arulesSequences package : Error in makebin(data, file) : 'sid' invalid - r

I am using arulesSequences package in R. The documentation is too little for the type of data that read_baskets function receives. I guess data should be in text (.txt) format. Column names are: "sequenceID", "eventID", "SIZE" and "items". My data has about 200,000 rows and looks like following in z.txt file:
1,1364,3,{12,17,19}
1,1130,4,{14,17,21,23}
1,1173,3,{19,23,9}
1,98,5,{14,15,2,21,5}
2,1878,4,{1,10,14,3}
2,1878,13,{1,12,14,15,16,17,18,19,2,21,24,25,5}
2,1878,1,{2}
I tried to use:
x <- read_baskets("z.txt", sep = ",",info =c("sequenceID","eventID","SIZE"))
s <- cspade(x,parameter = list(support = 0.001),control = list(verbose =
TRUE),tmpdir = tempdir())
but I get this error :
Error in makebin(data, file) : 'sid' invalid

The combination of sequenceID and eventID must be unique.
Otherwise you'll get one of these errors:
Error in makebin(data, file) : 'sid' invalid
Error in makebin(data, file) : 'eid' invalid
This implies further that the items in your .txt file (per sequenceID, eventID combination) must be in the same row and (possibly) be separated with the same separator as the rest of the .txt file. Therefore, the item column should be the last column.
Hope this helps!

Ok I found the problem, and I'm posting it in case that some one has the same problem. The problem is both SequenceID and eventID (first and second columns must be ordered blockwise. package mentions this point, but I only ordered the first column.

Related

R targets pipeline error: "Error : _paths_ missing files:" D:/path_to_my_file

I am learning to use targets within my current research project. I am still at the beginning of my data processing (and associated pipeline) but I get the following error when I try to use targets::tar_make():
> targets::tar_make()
✔ skip target raw_tits
• start target nnestling_data
ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
✖ error target nnestling_data
• end pipeline: 1.19 seconds
Error : _paths_ missing files: Table exported to D:/fmartin/Mes documents/projects/pubprivlands/analyses/ppl.tits/output/tables/tits_nestling_data.csv
✖ Problem with the pipeline.
ℹ Show errors: tar_meta(fields = error, complete_only = TRUE)
ℹ Learn more: https://books.ropensci.org/targets/debugging.html
Error:
! problem with the pipeline.
I truly don't understand why it doesn't work since there is no missing file. Here's how my current _targets.R looks like:
list(
# Make the workflow depends on the raw data file
targets::tar_target(raw_data_file, here::here("mydata", "ppl_dijon_tits_data.csv"),
format = "file"),
# Read the data and return a data.frame
targets::tar_target(raw_tits, ppl.tits::import_raw_tits_data()),
# Export the nestling aggregated data table
targets::tar_target(nnestling_data, ppl.tits::export_nestling_aggreg(), format = "file")
)
And the simple export function I'm calling in my last targets::tar_target():
export_nestling_aggreg <- function(){
aabb <- ppl.tits::aggreg_by_nest()
readr::write_csv2(x = aabb, file = here::here("output", "tables", "tits_nestling_data.csv"))
return(paste("Table exported to", here::here("output", "tables", "tits_nestling_data.csv"), sep = " "))
}
Could someone help me figure this one out?

TypeError: argmax(): argument 'input' (position 1) must be Tensor, not str

My code was working fine and when I tried to run it today without changing anything I got the following error:
TypeError: argmax(): argument 'input' (position 1) must be Tensor, not str
Would appreciate if help could be provided.
below is the code snippet where I am getting an error. I am using BERT mdoel
start_scores, end_scores = model(torch.tensor([input_ids]), # The tokens representing our input text.
token_type_ids=torch.tensor(
[segment_ids])) # The segment IDs to differentiate question from answer_text
# ======== Reconstruct Answer ========
# Find the tokens with the highest `start` and `end` scores.
answer_start = torch.argmax(start_scores)
answer_end = torch.argmax(end_scores)
In your line of code
start_scores, end_scores = model(torch.tensor([input_ids]),token_type_ids=torch.tensor([segment_ids]))
you have to make it:
start_scores, end_scores = model(torch.tensor([input_ids]),token_type_ids=torch.tensor([segment_ids]), return_dict=False).
It worked for me. I had the same problem.

Is there a way in R to add comma's to incorrect JSON format?

I'm trying to work with a JSON file in R, but unfortunately the JSON file is unreadable by jsonlite in its current state. It's missing commas between the objects(arrays elements?). My objective is to form a data frame from this almost-JSON file. Example JSON file, code, and result below.
[
{"Source":"ADSB","Id":43061,"FlightId":"N668XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}
{"Source":"ADSB","Id":43062,"FlightId":"N683XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}
{"Source":"ADSB","Id":43063,"FlightId":"N652XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450}
]
> jsondata = fromJSON("asdf.json")
Error in parse_con(txt, bigint_as_char) :
parse error: after array element, I expect ',' or ']'
"Heading":280,"Speed":124} {"Source":"ADSB","Id":43062,"Fl
(right here) ------^
After inserting comma's between the objects in the JSON file, it works no problem.
[
{"Source":"ADSB","Id":43061,"FlightId":"N668XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450},
{"Source":"ADSB","Id":43062,"FlightId":"N683XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450},
{"Source":"ADSB","Id":43063,"FlightId":"N652XX","Latitude":44.000083,"Longitude":-96.654788,"Alt":4450},
]
> jsondata = fromJSON("asdf.json")
> names(jsondata)
[1] "Source" "Id" "FlightId" "Latitude" "Longitude" "Alt"
How do I insert commas throughout this JSON file between all of the curvy brackets? (i.e. "}{" --> "},{"
Or is there another way for R to read my incomplete JSON file?
I'm less than a novice, so any help is much appreciated, thanks!!

Saving .maf file as a table

I am trying to save a .maf file as a table, but I always get the error below:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ‘structure("MAF", package = "maftools")’ to a data.frame
This is the code I am using:
library(maftools)
laml.maf <- "/Users/PC/mc3.v0.2.8.PUBLIC.maf"
laml = read.maf(maf = laml.maf)
write.table(laml, file="/Users/PC/tp53atm.txt")
I understand that the .maf file has several fields, but I am not sure how to isolate them to save as a table. Any help would be much appreciated!
The problem is, that the write.table function doesn't know how to deal with an object of class MAF.
However, you can access the underlying data like this:
write.table(laml#data, file="/Users/PC/tp53atm.txt")
But note that this way you will only export the raw data, whereas the MAF object contains various other meta data:
> slotNames(laml)
[1] "data" "variants.per.sample" "variant.type.summary" "variant.classification.summary"
[5] "gene.summary" "summary"
"maf.silent" "clinical.data"
>

R Write a dbf file

I want to create a dbf file to export a data frame to, I already tried:
write.dbf(MyDF,MyDF.dbf,factor2char = F)
but get the error code:
Error in write.dbf(MyDF, MyDF.dbf, factor2char = F) :
object 'MyDF.dbf' not found
I can tell why but I just can't find a solution.
The 2nd parameter should be a string. Try this:
write.dbf(MyDF,"MyDF.dbf",factor2char = F)
The error you are getting is that MyDF.dbf is being treated as a variable name and you haven't defined a variable with that name.

Resources